OnModify, OnValidate, with old values ....

Hi everyone, I’m having a bit of an issue with OnModify and OnValiday; hope you all can offer some advice. Note: All reference to triggers and code, below, is done in the TABLE C/AL code, NOT a FORM or CONTROL. I have three tables: t1, t2, t3 T2 has a field (field1) which has code in its “field1 - OnValidate()” trigger. This code uses T1 and itself(T2) to update T3. This was previously developed and works fine. Now what I want is when T1 is modified, I want it to run the validate trigger for T2.field1 so that T3 gets updated. I’m not adding anything to the existing code of the Field1 OnValidate() … I only want to trigger it. So in the OnModify() trigger of T1, I use a variable to T2, setranges, and then call T2.VALIDATE(Field1); Now this works … though not completely accurately. What I am getting is the previous (old) value of T1 written to T3. Everytime I change the value on T1, T1’s previous value is written to T3. I like the current design in that the code is in the table triggers rather than form triggers and I would rather keep it this way if possible. So, what is causing this and how would I correct this behaviour? Thanks for any comments and help. Cheers, Eric

Hi, to trigger the onValidate trigger of table t2, use the code t2.validate(t2.field1,value) in table t1 (onModify trigger).

Hi ECarmody I think your problem is that in T2 “field1 - OnValidate()” trigger, you are using .GET or .FIND on T1 to use it to update T3. But when you come to this OnValidte trigger from the T1 OnModify() trigger, by calling T2.VALIDATE(Field1); the change in T1 has not been modified to the database server yet (not until the OnModify trigger is completed). Then when you call T1.GET, you get the latest version of T1 saved to the server, which is not the one you wanted, but the previous one. This problem can be solved by using COMMIT before you call T2.VALIDATE in the T1 OnModify() trigger, or before you call T2.GET (or T2.FIND) in T2.Field1 OnValidate(). Using COMMIT, though, should be done with precautions. You need bo be convinced that your code can not possibly cause an error, because then COMMIT would prevent rollback. What makes this solution even less appealing, is that for this COMMIT to work properly, you have to call MODIFY at the beginning of the T1 OnModify() trigger !!! I would like to see a better solution, but anyway here is the way I imagine your code would look like. T1 - OnModify() MODIFY; // Ouch!!! COMMIT; T2.GET(…); T2.VALIDATE(Field1); Hope this helps.

Well… there are always different ways of doing things… and a lot of them without COMMIT… You can always do as follows: 1) on T2, create a variable type record subtype T1. 2) on T2, create a boolean variable (example useRecT1) 3) on T2, create a function that allows you changing the value of the variable useRecT1 4) on T2, modify the field validation function so if useRecT1 is true uses the T1 variable instead of getting the record from the table (best way is moving the validate code to a function, copying the function for modifying it to use a parameter T1 and change the validate code to be IF useRecT1 then function2(T1variable) else function1; 5) On T2 add a function to set the variable T1 6) On T1, modify the on validate as: T2.setT1variablefunction(Rec); T2.setUseRecT1Function(TRUE); T2.validate(Field); T2.setUseRecT1Function(FALSE); Regards,