Hi guys, Today we see how to create sales order header and Multiple lines for that header with X++ in ax 2012.
static void SalesOrder(Args _args)
{
SalesTable salesTableLoc;
SalesLine salesLineLoc;
InventDim inventDimLoc;
DaxSalesInformation daxsalesinformationloc;
NumberSeq numberSeq;
SalesFormLetter salesFormLetter;
container con;
int i=1;
;
ttsBegin;
// header creation
numberSeq = NumberSeq::newGetNum(SalesParameters::numRefSalesId());
numberSeq.used();
salesTableLoc.SalesId = numberSeq.num();
salesTableLoc.initValue();
salesTableLoc.CustAccount = "1001";CustAccount.valueStr();
salesTableLoc.initFromCustTable();
if (salesTableLoc.validateWrite())
{
salesTableLoc.insert();
info(strFmt("Sales Order created=%1",salesTableLoc.SalesId));
}
//Multiple line creation
con=msCtrl.getSelectedFieldValues();
if (salesTableLoc.RecId)
{
while (i<=conlen(con))
{
salesLineLoc.clear();
inventDimLoc.clear();
salesLineLoc.SalesId = salesTableLoc.salesid;
salesLineLoc.initFromSalesTable(salesTableLoc);
salesLineLoc.ItemId = conPeek(con,i); //SalesLine_ItemId.valueStr();
salesLineLoc.itemIdChanged();
we can use finddim method or Select statement;
//inventDimLoc.InventSiteId=InventDim_InventSiteId.valueStr();
//inventDimLoc.InventLocationId=InventDim_InventLocationId.valueStr();
//salesLineLoc.InventDimId=InventDim::findDim(inventDimLoc).inventDimId ;
select InventDimId from inventDimLoc
where inventDimLoc.InventLocationId==InventDim_InventLocationId.valueStr()
&& inventDimLoc.InventSiteId==InventDim_InventSiteId.valueStr();
salesLineLoc.InventDimId=inventDimLoc.InventDimId;
if (!salesLineLoc.validateWrite())
{
throw Exception::Error;
}
salesLineLoc.SalesQty = 2;//SalesLine_SalesQty.realValue();
salesLineLoc.modifiedField(fieldNum(salesLine, SalesQty));
salesLineLoc.SalesUnit='ea';//SalesLine_SalesUnit.valueStr();
salesLineLoc.SalesPrice=500;//SalesPrice.realValue();
salesLineLoc.modifiedField(fieldNum(salesLine, SalesPrice));
salesLineLoc.LineAmount = salesLineLoc.calcLineAmount();
salesLineLoc.setPriceDiscChangePolicy(PriceDiscSystemSource::ManualEntry,fieldNum(salesLine, SalesPrice));
salesLineLoc.createLine(true,true,true,true,true,true);
// we can over ride price and Quantity after sales line creation But it affects on CustConfirmJour.ConfirmAmount.
// salesLineLoc.createLine(true,true,false,true,true,true);
//salesLineLoc.SalesQty = SalesLine_SalesQty.realValue();
//salesLineLoc.SalesUnit=SalesLine_SalesUnit.valueStr();
//salesLineLoc.SalesPrice=SalesPrice.realValue();
//salesLineLoc.LineAmount = salesLineLoc.calcLineAmount();
//salesLineLoc.update();
i++;
info(strFmt("Sales line created-%1",salesLineLoc.ItemId));
}
salesTableLoc = SalesTable::find(salesTableLoc.salesid);
salesFormletter = SalesFormletter::construct(DocumentStatus::Confirmation);
salesFormLetter.update(salesTableLoc, systemDateGet());
}
Keep Daxing !!
No comments:
Post a Comment