28 Mar 2013

How to create Purchase Order through X++

In this post we will learn the below using X++ :

1) How to Create Purchase Order
2) How to Create Purchase Order Line
3) How to Post Purchase Order

static void PurchaseOrder(Args _args)
{
PurchTable pt;
PurchLine pline;
NumberSeq ns;
PurchID pid;
PurchFormLetter pl;
;
//Create Purchase Order
ns=NumberSeq::newGetNumFromCode(SalesParameters::numRefSalesId().NumberSequence);
pt.initValue();
pid=ns.num();
pt.PurchId=pid;
pt.OrderAccount="4202";
pt.initFromVendTable();
pt.insert();

//Create Purchase Line
pline.clear();
pline.PurchId=pid;
pline.ItemId="1109";
pline.createLine(NoYes::Yes,NoYes::Yes,NoYes::Yes,NoYes::Yes,NoYes::Yes,NoYes::Yes);
info("Purchase Order Created Sucessfully");

//Post the PO
pl=PurchFormLetter::construct(DocumentStatus::Invoice);
pl.update(PurchTable::find(sid),sid,SystemDateGet(),PurchUpdate::All,AccountOrder::None,false,true);
info("Posted Sucessfully");
}


No comments:

Create number sequence in D365 FO

Create the data type. Add code in the loadModule method of the appropriate NumberSeqModule subclass. Add a method to the module’s paramet...