How to Create Sales Order in Dynamics AX 2012 Through X++
How to Create Sales Order in Dynamics AX 2012 Through X++
static void createSalesOrder(Args _args)
{
SalesTable salesTable;
SalesLine salesLine;
InventDim inventDim;
NumberSeq numberSeq;
SalesFormLetter salesFormLetter;
SalesId salesId;
//Sales Table
numberSeq = NumberSeq::newGetNum(SalesParameters::numRefSalesId());
numberSeq.used();
salesId = numberSeq.num();
salesTable.SalesId = salesId;
salesTable.initValue();
salesTable.CustAccount = 'Account number';
salesTable.initFromCustTable();
if (salesTable.validateWrite())
{
salesTable.insert();
}
//Sales line
inventDim.clear();
inventDim.InventLocationId = '20';
inventDim.modifiedField(fieldNum(InventDim,InventLocationId));
inventDim = InventDim::findOrCreate(inventDim);
salesLine.clear();
salesLine.initValue(salesTable.SalesType);
salesLine.initFromSalesTable(salesTable);
salesLine.ItemId = '100000';
salesLine.initFromInventTable(InventTable::find(salesLine.ItemId));
salesLine.InventDimId = inventDim.inventDimId;
salesLine.SalesQty = 10;
salesLine.RemainSalesPhysical = salesLine.SalesQty;
salesLine.QtyOrdered = salesLine.calcQtyOrdered();
salesLine.RemainInventPhysical = salesLine.QtyOrdered;
//salesLine.SalesPrice = 20;
if (salesLine.validateWrite())
{
salesLine.insert();
}
//Post
salesFormLetter = SalesFormLetter::construct(DocumentStatus::Invoice);
salesFormLetter.parmSourceTable(SalesTable::find(salesId));
salesFormLetter.update(SalesTable::find(salesId),systemDateGet());
}
Comments
Post a Comment