thanks for your answer. Introdution has been done
How the codeunit is run? Hmm, I’d say ‘the normal way’.
I will post an easier part with the same problem:
User updates the description of an item (T27). Because I have already developed a function that updates several other items (related to the modified item) the function should update all other items in the same group. Reason for this function is just to create a lot of items based on this special item. The client sells shoes and does not want to create one item for each colour, size and model. It does not make sense to use ‘variants’ in this case.
So after updating (validate) the field description I call a codeunit in the OnValidate trigger of the item table (27). It runs the codeunit which looks for all relating items and ask the user if he wants to update all other shoes with the new description. If he accepts the codeunit simply copies the new description to all other shoes of this model. Really a simple job.
Code at the end of OnValidate Field ‘Description’ in Table 27:
IF “Base Item” THEN
(UpdateChilds is the selfmade codeunit whicht looks for linked items)
But the codeunit doesn’t ‘see’ the NEW value. It get’s the former value (like xrec) and copies the old value to all shoes.
There are two workarrounds to finish this job for the user:
- Say ‘No’ to the Confirm, Close the form, reopen it and validate the description again. Then say 'yes". Works perfectly.
- Move to another item, come back and validate again. Say ‘Yes’. Also successful
So my question is how to prevent that the codeunit looks on the old value. It seems that it runs simply too early.
Best wishes Tretroller_