Tuesday, 28 June 2016

Create new sales order in AX through code

static void createSalesOrder(Args _args)
{
    SalesTable salesTable;
    SalesLine salesLine;
    NumberSeq NumberSeq;
    ;
    NumberSeq = NumberSeq::newGetNum(SalesParameters::numRefSalesId());
    salesTable.SalesId = NumberSeq.num();
    salesTable.initValue();
    salesTable.CustAccount = '####';
    salesTable.initFromCustTable();
    salesTable.insert();

    salesLine.clear();
    salesLine.SalesId = salesTable.SalesId;
    salesLine.ItemId = 'P0001';
    salesLine.createLine(NoYes::Yes, // Validate
    NoYes::Yes, // initFromSalesTable
    NoYes::Yes, // initFromInventTable
    NoYes::Yes, // calcInventQty
    NoYes::Yes, // searchMarkup
    NoYes::Yes); // searchPrice

    info(strFmt('Sales Order %1 created', salesTable.SalesId));

}

1 comment:

  1. Hi
    I've tried with this code and I'm unable to assign SalesPrice (Unit price).
    Can you Please provide the solution to do that as if I assign the SalesPrice after calling that createLine(); that is becoming 0.

    Regards,
    Shashi

    ReplyDelete