Validate after Update?

Hi,

my task is to enter a value into a field via a form. Nothing special and easy. While the value is validated a codeunit is started to work with the new value. Everything is working fine, all calculations are executed perfectly.

But… of course there is a ‘but’…

The codeunit does use the xrec so it does not recognize that there is a new value in the table. When I validate the value a second time, everything works. But only at the second try.

How can I tell the system to first write the new value and after this execute the codeunit?

I do not want to use COMMIT because the codeunit checks if the value is allowed and rejects if not.

Things like SAVERECORD, BeforeValidateRecord etc. does not work. Or I did something wrong?

Thanks for help!

Tretroller_

Which is the codeunit? Is it a standard codeunit? And what is the code launching the codeunit?

The codeunit is a selfmade one which calculates the line discount depending on the values inthe sales line.

It is called in the OnValidate Trigger of the sales line. If the user validates the field the codeunit is called “Codeunit.Function(rec)”. As already posted it works fine but the codeunit is executed before the new value is written into the database. The codeunit calculates with the former value. If you validate the same value again everything ist fine.

First a big welcome to The Dynamics User Group. Please when you get a chance Write an introduction here.

Before being able to help you, as Kriki says, we need to see a snippet of thecode both calling and the codeunit. Also WHICH field is the Code in.

Just another point. COMMIT does not change any data in Navision, and in your curretn transaction, it actually has no effect, so adding COMMIT would not help. The only thing COMMIT does is activates the current Version of you transaction into the database.

Hi David,

thanks for your answer. Introdution has been done :wink:

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(“No.”);

(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:

  1. Say ‘No’ to the Confirm, Close the form, reopen it and validate the description again. Then say 'yes". Works perfectly.
  2. 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.

Enough information?

Best wishes Tretroller_