IF blnXXX THEN BEGIN CLEAR(pageXXX); pageXXX.SETTABLEVIEW(Rec); pageXXX.LOOKUPMODE :=TRUE; pageXXX.RUNMODAL; END;and the following code in the OnClose page trigger of the pop up page:
SalesHeader.GET(SalesHeader."Document Type"::Order,"No."); SalesHeader."Sell-to Customer Name" :=NewCustName; SalesHeader."Sell-to Customer Name 2" := NewCustName2; . . . IF SalesHeader.MODIFY THEN; COMMIT;When I run the Sales order, do a change in the pop up page and then click OK, I get the following erro message:
An attempt was made to change an old version of a Sales Header record.The record should be first reread from the database.This is a programming error.The debugger stops at the following instruction in trigger OnValidate of Sell- to Customer No.(function SelltoCustomerNoOnAfterValidat) in Sales Order page:
CurrPage.UPDATE;I can't figure out how to modify my code to make it work.
Comments
it's a typical case of concurrently modifying the same record you're working on. The dialog window commits the changes to the database... but you're still in the C/AL context of the table (and the record) that was modified. This leads to an error when you try to write back to the database yourself, because you were modifying an outdated version of the record.
How to do it correctly:
- invoke your dialog on a temporary record (you give the record on the call)
- close it with lookupok
- use the changed fields from the temporary record to do what you want to do.
in pseudocode:
There are some catches with temporary records. You should not use validation because you don't know where the code is executing on. So, in this case, I would probably have a look of what needs to be entered/selected, and either build a table for it (costly, should be justified) or use SetData/GetData methods on the page. You would need to write them yourself of course. With SetData/GetData the code would look like this:
with best regards
Jens