I found this issue with 2009 sp1 finsql.exe with build 29626. xRec and Rec are the same in onmodify trigger when validated from code. It works when manually modified from form.
My code looks at follows.
On purchline onmdify trigger()
if xRec."Direct Unit Cost" <> "Direct Unit Cost" then
Error('Direct Unit Cost value has changed.');
My code in CU
Purchline.get("Document type","No.");
Purchline.validate("direct Unit Cost",23);
Purchline.modify(true);
The error is not triggered.
Anybody knows why?
Ahmed Rashed Amini
Independent Consultant/Developer
blog:
https://dynamicsuser.net/nav/b/ara3n0
Comments
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
xRec and Rec are the same if not triggered from GUI. Isn't that always the problem? I guess, I have seen this before.
Regards
Thomas
Never stop learning
Van Vugt's dynamiXs
Dutch Dynamics Community
I had removed the code to check xrec and rec.
Was this a recent change in the executables?
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
Note: removing the code checking Rec against xRec might bring cause unwanted behaviour in some instances. Be sure you really want to do this. This kind of check: in general is done, to only execute code when the user really has changed the value. If the user has retyped a valu (so actually it stays the same) the code will not be executed.
Never stop learning
Van Vugt's dynamiXs
Dutch Dynamics Community
It's been a while that I have built a mod that compared Rec to xRec. But this should behave the same way if you are entering an order or creating the record through code. The whole point of validating the field is that you are ensuring that same business logic is run.
I'll have to report this MS.
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
https://connect.microsoft.com/dynamicss ... ous-record
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
Never stop learning
Van Vugt's dynamiXs
Dutch Dynamics Community
You want to guarantee that the same logic is run when creating a record manually or through code validating the record and calling
modify(True);
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
Never stop learning
Van Vugt's dynamiXs
Dutch Dynamics Community
"Never memorize what you can easily find in a book".....Or Mibuso
My Blog
Never stop learning
Van Vugt's dynamiXs
Dutch Dynamics Community
If I key a new order from “sales&marketing” , “sales”, “customer” and here you choose in the customer card menu item “sales” and “order” then hit F3 for insert, the system is not reflecting the correct payment discount.
During debugging I found that inserting a new order this way, xRec was actually equal to another order and this code in the Sales Header.Payment Terms Code OnValidate
would cause unpredictiable results depending on the "bogus" value is xRec.
IF xRec."Document Date"="Document Date" THEN
VALIDATE("Payment Discount %",PaymentTerms."Discount %")
END;
As a work around, I modified the Sales Header on Insert trigger and added this line afer
InsertMode := TRUE;
//
xRec := Rec;
//
I was able to duplicate this in Cronus NAV 2009 sp1. You have to be in the debugger to see that xRec is different the Rec because of the date logic in Cronus.
Any pros or cons on this temporary fix would be appreciated.
Joe