How to create quotation in Dynamics AX 2012 Through X++
How to create quotation in Dynamics AX 2012 Through X++
static void createQuotation(Args _args)
{
AxSalesQuotationTable axSalesQuotationTable;
AxSalesQuotationLine axSalesQuotationLine;
InventDim inventDim;
//Header
axSalesQuotationTable = new AxSalesQuotationTable();
//if smmQuotationAccountType::BusRelAccount
axSalesQuotationTable.parmBusRelAccount('5001');
//if smmQuotationAccountType::CustAccount
//axSalesQuotationTable.parmCustAccount('10001');
axSalesQuotationTable.save();
//lines
inventDim.clear();
inventDim.InventSiteId = '01';
inventDim.modifiedField(fieldNum(InventDim,InventSiteId));
inventDim = InventDim::findOrCreate(inventDim);
axSalesQuotationLine = new AxSalesQuotationLine();
axSalesQuotationLine.axSalesQuotationTable(axSalesQuotationTable);
axSalesQuotationLine.parmQuotationId(axSalesQuotationTable.parmQuotationId());
axSalesQuotationLine.parmItemId('10001');
axSalesQuotationLine.parmSalesQty(1);
axSalesQuotationLine.parmSalesPrice(100);
axSalesQuotationLine.parmInventDimId(inventDim.inventDimId);
axSalesQuotationLine.parmSalesUnit('PC');
axSalesQuotationLine.save();
ttsCommit;
}
static void createQuotation(Args _args)
{
AxSalesQuotationTable axSalesQuotationTable;
AxSalesQuotationLine axSalesQuotationLine;
InventDim inventDim;
//Header
axSalesQuotationTable = new AxSalesQuotationTable();
//if smmQuotationAccountType::BusRelAccount
axSalesQuotationTable.parmBusRelAccount('5001');
//if smmQuotationAccountType::CustAccount
//axSalesQuotationTable.parmCustAccount('10001');
axSalesQuotationTable.save();
//lines
inventDim.clear();
inventDim.InventSiteId = '01';
inventDim.modifiedField(fieldNum(InventDim,InventSiteId));
inventDim = InventDim::findOrCreate(inventDim);
axSalesQuotationLine = new AxSalesQuotationLine();
axSalesQuotationLine.axSalesQuotationTable(axSalesQuotationTable);
axSalesQuotationLine.parmQuotationId(axSalesQuotationTable.parmQuotationId());
axSalesQuotationLine.parmItemId('10001');
axSalesQuotationLine.parmSalesQty(1);
axSalesQuotationLine.parmSalesPrice(100);
axSalesQuotationLine.parmInventDimId(inventDim.inventDimId);
axSalesQuotationLine.parmSalesUnit('PC');
axSalesQuotationLine.save();
ttsCommit;
}
Thank you for sharing your code.
ReplyDeleteBelow is a modified example which reads from a file.
static void SSS_FileReadCreateQuote(Args _args)
{
CommaIO ioIn;
FileNameOpen filenameIn;
Dialog d;
DialogField dfFileIn;
DialogField dfSkip;
DialogField dfInsBrand;
DialogField dfUpdItem;
container inLine;
ItemId itemId;
InventTable inventTable;
SalesQuotationTable salesQuotationTable;
SalesQuotationLine salesQuotationLine;
InventDim inventDim;
AxSalesQuotationTable axSalesQuotationTable;
AxSalesQuotationLine axSalesQuotationLine;
CustTable custTable = custTable::find("016463");
;
d = new dialog('Create quote from file');
dfFileIn = d.addField(extendedtypestr(FilenameOpen), 'Read from');
dfSkip = d.addField(enumStr(NoYes), 'Skip first line');
window 20,5 at 0, 0;
if (d.run() && dfFileIn.value())
{
ioIn = new CommaIo(dfFileIn.value(), 'R');
if (! ioIn)
throw error(strfmt("@SYS18678", dfFileIn.value()));
ioIn.inFieldDelimiter(",");
if(dfSkip.Value() == NoYes::Yes) //Skip first line
inLine = ioIn.read();
inLine = ioIn.read();
inventDim.InventSiteId = 'SSS';
inventDim.InventLocationId = '10';
inventDim = InventDim::findOrCreate(inventDim);
axSalesQuotationTable = new AxSalesQuotationTable();
axSalesQuotationTable.parmCustAccount(custTable.AccountNum);
axSalesQuotationTable.parmCurrencyCode(custTable.Currency);
axSalesQuotationTable.save();
info(strFmt("%1", axSalesQuotationTable.parmQuotationId()));
while (inLine)
{
itemId = conPeek(inLine, 1);
inventTable = inventTable::find(itemId);
info(strFmt("%1", inventTable.ItemId));
if (inventTable)
{
axSalesQuotationLine = new AxSalesQuotationLine();
axSalesQuotationLine.parmQuotationId(axSalesQuotationTable.parmQuotationId());
axSalesQuotationLine.axSalesQuotationTable(axSalesQuotationTable);
axSalesQuotationLine.parmItemId(inventTable.ItemId);
axSalesQuotationLine.parmSalesQty(1);
axSalesQuotationLine.parmCostPrice();
axSalesQuotationLine.parmInventDimId(inventDim.inventDimId);
axSalesQuotationLine.parmcurrencyCode(custTable.Currency);
axSalesQuotationLine.save();
}
inLine = ioIn.read();
}//end fil*/
//costprice is not set so we set it afterwards.
ttsBegin;
while select forUpdate SalesQuotationLine
where SalesQuotationLine.QuotationId == axSalesQuotationTable.parmQuotationId()
{
salesQuotationLine.CostPrice = SalesQuotationLine.mcrCalcCostPrice();
salesQuotationLine.update();
}
ttsCommit;
info('over and out');
}
}