Purpose:
The purpose of this document is to illustrate how we can confirm purchase orders in X++ using PurchParmTable table and PurchFormLetter class.
Business requirement:
Ability to confirm purchase order automatically. As of now Standard AX offers manual purchase order confirmation by clicking Procurement and sourcing > Common > Purchase orders > All purchase orders > Purchase > Generate > Confirm.
Assumptions:
The purchase order is created, lines are added and the Approval status is “Approved”.
Development:
Please find below the job to create and post product receipt against a purchase order in X++:
// Developed on 28 Dec 2015 by Muhammad Anas Khan // Blog: dynamicsaxinsight.wordpress.com // LinkedIn: pk.linkedin.com/in/muhammadanaskhan // Description: Ability to confirm purchase order static void makPurchPurchaseOrderConfirm(Args _args) { PurchFormLetter purchFormLetter; PurchFormletterParmData purchFormLetterParmData; PurchParmUpdate purchParmUpdate; PurchParmTable purchParmTable; PurchParmLine purchParmLine; PurchTable purchTable; PurchLine purchLine; PurchId purchId; Num packingSlipId; purchId = "000441"; packingSlipId = "MAK3001"; purchTable = PurchTable::find(purchId); ttsBegin; // Create PurchParamUpdate table purchFormLetterParmData = PurchFormletterParmData::newData( DocumentStatus::PurchaseOrder, VersioningUpdateType::Initial); purchFormLetterParmData.parmOnlyCreateParmUpdate(true); purchFormLetterParmData.createData(false); purchParmUpdate = purchFormLetterParmData.parmParmUpdate(); // Set PurchParmTable table purchParmTable.clear(); purchParmTable.TransDate = SystemDateGet(); purchParmTable.DocumentDate = SystemDateGet(); purchParmTable.Ordering = DocumentStatus::PurchaseOrder; purchParmTable.ParmJobStatus = ParmJobStatus::Waiting; purchParmTable.PurchId = purchTable.PurchId; purchParmTable.PurchName = purchTable.PurchName; purchParmTable.DeliveryName = purchTable.DeliveryName; purchParmTable.DeliveryPostalAddress = purchTable.DeliveryPostalAddress; purchParmTable.OrderAccount = purchTable.OrderAccount; purchParmTable.CurrencyCode = purchTable.CurrencyCode; purchParmTable.InvoiceAccount = purchTable.InvoiceAccount; purchParmTable.ParmId = purchParmUpdate.ParmId; purchParmTable.insert(); purchFormLetter = PurchFormLetter::construct(DocumentStatus::PurchaseOrder); purchFormLetter.transDate(systemDateGet()); purchFormLetter.proforma(false); purchFormLetter.specQty(PurchUpdate::All); purchFormLetter.purchTable(purchTable); // This is the ID we hard code as the product receipt ID, if we do the posting via UI // user would have the option to manually enter this value purchFormLetter.parmParmTableNum(purchParmTable.ParmId); purchFormLetter.parmId(purchParmTable.ParmId); purchFormLetter.purchParmUpdate(purchFormLetterParmData.parmParmUpdate()); purchFormLetter.run(); ttsCommit; }
