modify(Quantity) { trigger OnAfterValidate() var PurchHeader: Record "Purchase Header"; begin PurchHeader.Reset(); PurchHeader.SetRange("Document Type", PurchHeader."Document Type"::Order); PurchHeader.SetRange("No.", Rec."Document No."); If PurchHeader.Findfirst() then Rec.Validate(MY_AssetID, PurchHeader.MY_AssetID); //[b]Modify(true);[/b]//*LINE DOES NOT EXIST ERROR AS LINE NOT INSERTED AT THIS POINT IF NEW LINE end; }[img]https://us.v-cdn.net/5022383/uploads/editor/wd/99u184yecjmk.png[/img]
samantha73 wrote: »Hi Guys
I have this code on purchase line Onvalidate on quantity field as a table extension on purchase line table. With Modify statement it doesn't workmodify(Quantity) { trigger OnAfterValidate() var PurchHeader: Record "Purchase Header"; begin PurchHeader.Reset(); PurchHeader.SetRange("Document Type", PurchHeader."Document Type"::Order); PurchHeader.SetRange("No.", Rec."Document No."); If PurchHeader.Findfirst() then Rec.Validate(MY_AssetID, PurchHeader.MY_AssetID); //[b]Modify(true);[/b]//*LINE DOES NOT EXIST ERROR AS LINE NOT INSERTED AT THIS POINT IF NEW LINE end; }[img]https://us.v-cdn.net/5022383/uploads/editor/wd/99u184yecjmk.png[/img]
Not sure why the line does not exist as quantity is not one of the primary keys? When Modiy statement is commented out it works but trying to understand at what point the line is inserted
Answers
I think you are doing it wrong.
You have to subscribe to an event subscriber, not "modify" quantity field which I think modifies the behaviour, something like:
You are getting the error because the record doesn't exist yet. Purchase Order Subform has "DelayedInsert = true" property, meaning the record is not actually inserted until you leave the line.
Your solutions would be to either check if the line exists first before modifying (if it doesn't exist, then no need to modify), or use OnBeforeValidate event and not modify at all.