Monday, February 19, 2024

Working with change management enabled purchase orders using X++ in D365 Finance and Operations

 

  //Change the purchase order from confirmed status to draft.   

                        Args args=new Args();

                        args.record(purchTable);

                        args.parmEnum(VersioningAction::RequestChange);

                        VersioningPurchaseOrder::main(args);

//Do update on purchase order

// write your logic

 // Tax is needed to be calculated first or else the Accounting Distribution allocation factor will not be calculated correctly.

                        PurchTotals::newPurchTable(purchTableLocal).calc();

                        // Submit to source document processor to perform GL budget check before confirming the comment dialog.

                        // This gives the approver a chance to cancel their action if there is any budget error or warning.

                        SourceDocumentProcessorFacade::submitOnDemandSourceDocumentImpl(purchTableLocal);

                        VersioningPurchaseOrder versioningPurchaseOrder;

                        versioningPurchaseOrder = VersioningPurchaseOrder::newPurchaseOrder(purchTableLocal);

//Submit workflow after change.

                        versioningPurchaseOrder.submitChangeRequest();

//Auto approve workflow

                        versioningPurchaseOrder.approveChangeRequest();

//Once it's approved then confirm the purchase order. 

                        if (purchTableLocal.DocumentState == VersioningDocumentState::Approved)

                        {

                            //Auto confirm the purchase order.

                            PurchFormLetter purchFormLetter;

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

                            PurchaseOrderId purchOrderDocNum = strFmt('%1-%2', purchTableLocal.PurchId, VendPurchOrderJour::numberOfPurchaseOrderVersions(purchTableLocal)+1);

                            purchFormLetter.update(purchTableLocal, purchOrderDocNum);

                        }

No comments:

Post a Comment