i just had a look at table 37 (invoicelines). there are two fields (“amount” and “amount incl. VAT”), both have code in the OnValidate-Trigger, and both enter data into the other field (“amount” calculates the amount including VAT, and “amount incl. VAT” calculates the amount without VAT). So one trigger should execute the other. Obviously this isn’t that way and this loop has an end. So: when does the system execute the trigger “OnValidate” ? And why does this work, that one trigger calculates the value of the other field ?? I’m a little confused about that… Stefan Weinreich Billing Analyst
They are not interfering each other because in both triggers there is no call to VALIDATE function for the other field. So the other trigger is never executed. If you update Amount from the Sales Orders form the OnValidate trigger for the Amount field is executed, but since it only assigns (:=) value to the “Amount incl. VAT” field without using SalesLine.VALIDATE(“Amount incl. VAT”, “Amount” + some-vat) the “Amount incl VAT” OnValidate trigger is not executed. You use VALIDATE function to call the OnValidate trigger for the field - for example - SalesLine.VALIDATE(Amount, 100);- it will assign the value of 100 to the field Amount and execute the OnValidate trigger. Exactly the same as Amount := 100; and calling SalesLine.VALIDATE(Amount); E.g. the only if VALIDATE(Field) function is called somewhere in the code the OnValidate trigger for the field is executed. That’s not the case in the table 37s fields “Amount” and “Amount inlc. VAT” - only one of the triggers is called and it assigns a value to the other field. Hope this helps!
Hey Nikola, it helps understanding the way navision works. But - in my understanding the system executes the trigger of a field, when a record is inserted or modified ?! Or is only trigger OnInsert, OnModify or OnDelete of a table executed, but not the OnValidate-Trigger of the field ? What happens, if i fill a field of a table manually ? Is then OnValidate executed ? What is, if a report or form fills the fields ? Stefan Weinreich Billing Analyst
Hi Stefan, what do you mean with “manually”? Use the object designer on a table and klick “run”. If you fill out anything in any field (because you are working in a form) the apllication will trigger the “on validate”-trigger. F2 twice on a field will trigger as well. If the field is filled out by a report e.g.: SalesLine.quantity := 10; SalesLine.modify; the OnValidate trigger of the field is not in use. Even the OnModify rigger will not be used (you have to use SalesLine.modify(true); if you want to use the OnModify trigger). To trigger OnValidate in a report you have to use this syntax: SalesLine.validate(Quantity,value); Regards Walter
Hi Stefan, Nikola is right - you there is a difference between executing a trigger and executing the code on that trigger. System will NOT execute the code on a trigger if you not ask for that explicitly. Example : If you write Rec.INSERT - the system will just insert a new record into a table (without executing the code on that trigger !!!), but if you write Rec.INSERT(TRUE) - you’ll have that code executed ! The same situation with a OnValidate trigger - if you use “:=”, system will NOT execute the code on a OnValidate trigger. In order to do that you need to use that: VALIDATE(YourFieldName,YourNewValue); That command “emulates” a users action when he changes the value of the field in a form(for example). Best regards, DMC
Hi all! To make things even more clear, I would like to paraphrase Stefan’s first question in the following way: does the assignment operator… “Amount Including VAT” := ROUND(Amount + “VAT Base Amount” * “VAT %” / 100,Currency.“Amount Rounding Precision”); …in the OnValidate trigger of the Amount field cause execution of the OnValidate trigger of Amount Including VAT field? The answer is: No, it does not. So, there is no problem with looping. The answer for the second question (does system executes the trigger of the field, when a record is inserted or modified?) is: no, it does not. When RECORD is inserted or modified, the trigger of the FIELD is not executed (note the caps). About filling fields ‘manually’: yes, the OnValidate trigger of the field you worked with is called as soon as you try to leave the field. And about manipulating with a field value from the code: assignment operator skips the OnValidate trigger. To execute it use Validate() function. So, it brings flexibility to development process: you may or may not use the functionality of the OnValidate trigger when developing your application. Best regards
thanks to all it makes the system more transparent to me. Stefan Weinreich Billing Analyst