Creating Sales Orders via X++

For beginner AX developers, I’m listing some codes which will help someone to create Sales Orders (Similar can be applied to PO) via X++ codes. This may be helpful to new Developers. [Level 200]

Some important Objects which are to be referred and understood are:
-Tables\SalesTable
-Tables\SalesLine
-Tables\InventDim
-Tables\CustTable
-Tables\InventTable
-Classes\SalesTableType {The InventType Hierarchy}

Sample Code [Very basic]

static void SalesOrderCreation(Args _args)
{
SalesTable salesTable;
NumberSeq NumberSeq;
SalesLine salesLine;
InventDim IDim;
;
ttsbegin;
NumberSeq = NumberSeq::newGetNumFromCode(SalesParameters::numRefSalesId).numberSequence);
//=======Table=======
salesTable.SalesId = NumberSeq.num();
salesTable.initValue();
salesTable.CustAccount = “4000”; //Enter Customer Acount
salesTable.initFromCustTable();
salesTable.InventLocationId = “GW”;
salesTable.insert();
//========Line=======
salesLine.clear();
salesLine.SalesId = salesTable.SalesId;
salesLine.ItemId = “IS2082SAIL”; //Enter Item ID
IDim.InventColorId =”CU”; //Enter Item Dimensions
IDim.InventLocationId = “GW”;
IDim = InventDim::findOrCreate(IDim);
salesLine.InventDimId = IDim.inventDimId;
salesLine.createLine(NoYes::Yes,
NoYes::Yes,
NoYes::Yes,
NoYes::Yes,
NoYes::Yes,
NoYes::Yes);
//===================
ttscommit;
Info(salesTable.SalesId);
}


The above code is very basic but will help you with the concepts and the same can be extended to create PO

Happy DAX-ing 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *