Tuesday, 8 April 2014

Sales order creation and post through X++ in AX 2012

static void SalesOrderCreate(Args _args)
{
    SalesTable          salesTable;
    SalesLine           salesLine;
    InventDim           inventDim;
    NumberSeq           numberSeq;
    SalesFormLetter     salesFormLetter;
    ttsBegin;
    numberSeq = NumberSeq::newGetNum(SalesParameters::numRefSalesId());
    numberSeq.used();
    salesTable.SalesId = numberSeq.num();
    salesTable.initValue();
    salesTable.CustAccount = '1001';
    salesTable.initFromCustTable();
    salesTable.InventLocationId = 'ANNAPOL';
    if (!salesTable.validateWrite())
    {
        throw Exception::Error;
    }
    salesTable.insert();
    salesLine.SalesId = salesTable.SalesId;
    salesLine.ItemId = '0001';
    salesLine.createLine(true, true, true, true, true, true);
    inventDim.InventLocationId = 'ANNAPOL';
    inventdim = InventDim::findOrCreate(inventDim);
    salesLine.InventDimId = inventDim.inventDimId;
    ttsCommit;
    info(strFmt("Sales order '%1' has been created", salesTable.SalesId));
    
    salesFormLetter = SalesFormLetter::construct(DocumentStatus::Confirmation);
    salesFormLetter.update(salesTable);
    info('salesorder updated to confirmation');
}
some useful links:
http://ansartroops.wordpress.com/2012/01/11/x-code-to-create-sales-order-and-post-the-invoice/

No comments:

Post a Comment