Triggers and Data Consistency

As all you know, in C/AL we can use INSERT, MODIFY, DELETE, … with or without the parameter ([RunTrigger]) to force (TRUE) or avoid (FALSE) the execution of the corresponding trigger. I have notice that in some fields the OnValidate trigger contains the MODIFY command with no parameter (that means FALSE) so if this is the last field you modify on the form, no OnModify trigger gets executed when you leave the record, so you can’t assure that any data consistency C/AL code in this triggers will be executed. Don’t you think it will be a good idea that this triggers get always executed, and the trigger having a parameter like “UserRequested”, so we can write code like **OnModify(UserRequested bool)** IF UserRequested THEN ... <your code> // only executed if MODIFY(**TRUE**) ELSE ... <your code> // only executed if MODIFY(**FALSE**) END; ... <other code> // always executed and be sure it will always gets executed (or not, using this parameter).

quote:


Originally posted by JSoage
I have notice that in some fields the OnValidate trigger contains the MODIFY command with no parameter (that means FALSE) so if this is the last field you modify on the form, no OnModify trigger gets executed when you leave the record, so you can’t assure that any data consistency C/AL code in this triggers will be executed.


I’m not quite sure I follow this - please examplify. The OnModify() trigger ALWAYS gets called when leaving a modified record in a form.

Sure the idea is useful … And there are many more programming related stuff I would like to see an improvement in. But I don’t think MS will now spend a lot of effort anymore in making our lives as a programmer more easy …

quote:


Originally posted by Steffen Voel I’m not quite sure I follow this - please examplify. The OnModify() trigger ALWAYS gets called when leaving a modified record in a form.


You can test as follows: 1 - On **Table 18 - Customer** modify as shown **Name - OnValidate()** IF ("Search Name" = UPPERCASE(xRec.Name)) OR ("Search Name" = '') THEN "Search Name" := Name; // +++ MODIFY; // <<< Add this // --- 2 - Go to Customer Card Form and select a customer with "Last Date Modified" diferent from today's date. 3 - Modify the field "Name" and move to next record 4 - Go back to modified customer and look at - "Name": Modified - "Last Date Modified": Not modified 5 - Go to Customer / Contact and look at - "Name": Not modified These two <not modified> fields should be modified if the OnModify trigger were called. 6 - Now modify the field "Address" and move to next record 7 - Go back to modified customer and look at - "Name": <Same as before> - "Last Date Modified": <<Modified>> 8 - Go to Customer / Contact and look at - "Name": <<Modified>> - "Address": <<Modified>> This time the OnModify trigger was called. There are MODIFY, INSERT, DELETE, … like this in the application, so if you add some code in this triggers don’t be confident it will be executed.

quote:


Originally posted by janpieter Sure the idea is useful … And there are many more programming related stuff I would like to see an improvement in. But I don’t think MS will now spend a lot of effort anymore in making our lives as a programmer more easy …


I am sure all we have great ideas, but I am talking about “Data Integrity” (see also http://www.mbsonline.org/forum/topic.asp?TOPIC_ID=11549) and from the End User point of view this could be a big, big problem.

It is a good point. Most database systems provide tiggers that will always execute no matter what. Navision lacks this and many features could be better and more simply implemented if they were present. It might come if a specfic feature required it, and this very nearly made it into 4.0, but not quite.

After some more testing I got surprised … the problem occurs only on the Navision DB, tested the same example in SQL Option and [:0][:0] the trigger is called [:0][:0] but only happens editing in a form, not if the command is called in a Report, CodeUnit, …