AX 4 -- PurchFormLetter.update() only partially updating PO

Hello all,

I am beginning to troubleshoot an issue on AX4 in which a PO is confirmed and then directly updated to invoice status via code.

In many cases, the process works flawlessly. In a few, seemingly random, cases it will update the document status to Purchase Order, and then it will update several of the PO Lines to Invoiced status, but not all.

The code is wrapped in a transaction, so I don’t believe an error is being thrown. Below is the code, if you have any suggestions or ideas on how it could be possible that some lines are invoice updated while others are not, I am all ears!

Grazie,
S

invoiceNum = “Inv_” + pOrder.PurchId;

//Post PO

pflPo = PurchFormLetter::construct(DocumentStatus::PurchaseOrder);

pflPo.update( pOrder // Purchase record Buffer

, invoiceNum // Packing Slip Number

, systemdateget() // Transaction date

);

pOrder.reread();

if (pOrder.DocumentStatus == DocumentStatus::PurchaseOrder

|| pOrder.DocumentStatus == DocumentStatus::Invoice)

{

//Post PO Invoice

if(pOrder.DocumentStatus == DocumentStatus::PurchaseOrder)

{

pflInvoice = PurchFormLetter::construct(DocumentStatus::Invoice);

pflInvoice.update( pOrder // Purchase record Buffer

, invoiceNum // Invoice Number

, systemdateget() // Transaction date

);

}

pOrder.reread();