HOW TO CREATE PURCHASE ORDER IN MICROSOFT DYNAMICS AX 2012
13 Oct 2014
Hi Guys,
In this post I’ll show you how to create purchase order in Microsoft Dynamics AX 2012 using X++ code (for those of you who aren’t familiar with it).
First off lets create the job that will accomplish the Create Purchase Order in Microsoft Dynamics AX 2012 task.
static void CreatePurchaseOrder(Args _args) {
NumberSeq numberSeq;
Purchtable tbl_purchtable;
PurchLine tbl_purchLine;
PurchFormLetter purchFormLetter;
;
ttsbegin;
// Now let’s create the number sequence object that will generate the purchase order id
numberSeq = NumberSeq::newGetNumFromCode(purchParameters::numRefPurchaseOrderId().NumberSequence, true);
// Next we’ll create the Purchase Order values
tbl_purchtable.initValue();
tbl_purchtable.PurchId = numberSeq.num();
tbl_purchtable.OrderAccount = ‘4000’;
tbl_purchtable.initFromVendTable();
if (!tbl_purchtable.validateWrite()) {
throw Exception::Error;
}
tbl_urchtable.insert();
// And the Purchase Order line items
tbl_purchLine.PurchId = tbl_purchtable.PurchId;
tbl_purchLine.ItemId = ‘LW24GG’;
tbl_purchLine.createLine(true, true, true, true, true, false);
ttscommit;
// Now let’s post the Purchase Order
// If you want to post the packing slip, then change the DocumentStatus to “PackingSlip”
purchFormLetter = purchFormLetter::construct(DocumentStatus::Invoice);
// Next we’ll update the method parameters in sequence i.e.
// Purchase record Buffer
// Invoice Number
// Transaction date
purchFormLetter.update(tbl_purchtable,”Inv_” + tbl_purchTable.PurchId, systemdateget());
// As I mentioned before, if you want to post packing slip, change the DocumentStatus to “PackingSlip”
if (tbl_purchTable::find(tbl_purchTable.PurchId).DocumentStatus == DocumentStatus::Invoice) {
info(strfmt(“Invoiced journal for purchase order %1”, tbl_purchTable.PurchId));
}
}
And that’s it!
About Folio3 Dynamics Services
FDS (Folio3 Dynamics Services) is a dedicated division of Folio3 that specializes in Microsoft Dynamics AX, Dynamics CRM, Dynamics NAV and Dynamics GP based development, customization and integration services. Our main focus is on Enterprise Mobility. We firmly believe that opening up Microsoft Dynamics AX and other products to iOS Android, Windows 8 and Windows Phone users will have a huge impact on organizational agility and productivity.
If you have a Dynamics AX based development project you’d like to discuss or would like to know more about our Dynamics AX development services, please get in touch with us.