Hello All,
On Codeunit 74, we added a new code in the function - CreateInvLines(.....)
PurchHeader."Your Reference" := PurchRcptHeader."Order No.";
PurchHeader.MODIFY;
and on Codeunit 90, we added the code to assign Your Reference Value to PurchInvHeader.Order No.
But we are getting the following error when posting,
An attempt was made to change an old version of a Purchase Header record. The record should first be reread from the database. This is a programming error.
Identification fields and values:
Document Type='Invoice',No.='XXXXXXXX'
0
Answers
This error happens if you try to MODIFY two separate copies of the same record in the code.
This usually happens if you pass a record to a function, the function parameter does not use VAR, and then you modify the record inside the function, and later on in the code which called the function.
To show you on an example. When a record is passed into a function which does not have the rec parameter declared as VAR NAV creates a copy of it. When you modify a record inside the function you effectively create a scenario as in the example above.
Slawek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
I did not post the exact solution. I posted an explanation what is happening and one of possible causes. This is your system, your code modifications, and it is up to you to find the bug. Knowing what and why is happening should make it easier for you.
Please don't expect us to pinpoint the line of the code causing problem, especially if you post two line of code. I could tell you take the MODIFY off in the code you've posted - it would probably help with the problem you have now, but most likely you would get another problem instead, for example the PurchHeader."Your Reference" field wouldn't be updated anymore.
Slawek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03