Friday, 16 February 2018

How to create sales order using x++ code in Ax 2012

Creating sales order using x++ code 


List of tables and classes affected during sales order

    SalesTable salesTable;
    NumberSeq NumberSeq;
    SalesId sid;
    SalesLine sl;
    SalesFormLetter salesFormLetter;

Creating header details during sales order creation

    NumberSeq =NumberSeq::newGetNum(SalesParameters::numRefSalesId() , true);
    sid=NumberSeq.num();
    salesTable.SalesId = sid;
    salesTable.initValue();
    salesTable.CustAccount = "US-006";
    salesTable.CurrencyCode = "USD";
    salesTable.SalesGroup = "1";
    salesTable.initFromCustTable();
    salesTable.insert();

Adding line item in Sales line 

    sl.SalesId=sid;
    sl.ItemId="1000";
    sl.InventDimId="000458";
    sl.PriceUnit=100.00;
    sl.SalesQty=1;
    sl.CreateLine(NoYes::Yes,NoYes::Yes,NoYes::Yes,NoYes::Yes,NoYes::Yes,NoYes::Yes);

    info("Sales Order Created with Line");

While posting sales order 

    salesFormLetter=SalesFormLetter::construct(DocumentStatus::PackingSlip);
    salesFormLetter.update(SalesTable::find(sid));
    salesFormLetter.update(salesTable,systemDateGet(),SalesUpdate::All,AccountOrder::None,                NoYes::No,NoYes::Yes);
    info("Sales Order Status is Delivered");

While creating sales order invoice

    salesFormLetter=SalesFormLetter::construct(DocumentStatus::Invoice);
    salesFormLetter.update(SalesTable::find(sid));
    info(strFmt("%1 Sales Order Posted and Final Status is Invoiced",salesTable.SalesId));


Code: 

static void CreateSalesOrder(Args _args)

{

    //Developer : Rajaram E

    SalesTable salesTable;
    NumberSeq NumberSeq;
    SalesId sid;
    SalesLine sl;
    SalesFormLetter salesFormLetter;
    ;
    NumberSeq =NumberSeq::newGetNum(SalesParameters::numRefSalesId() , true);
    sid=NumberSeq.num();
    salesTable.SalesId = sid;
    salesTable.initValue();
    salesTable.CustAccount = "US-006";
    salesTable.CurrencyCode = "USD";
    salesTable.SalesGroup = "1";
    salesTable.initFromCustTable();
    salesTable.insert();

    //Create the Sales Line with the created Sales Order
    sl.SalesId=sid;
    sl.ItemId="1000";
    sl.InventDimId="000458";
    sl.PriceUnit=100.00;
    sl.SalesQty=1;
    sl.CreateLine(NoYes::Yes,NoYes::Yes,NoYes::Yes,NoYes::Yes,NoYes::Yes,NoYes::Yes);

    info("Sales Order Created with Line");

    //Posting Sales Order
    salesFormLetter=SalesFormLetter::construct(DocumentStatus::PackingSlip);
    salesFormLetter.update(SalesTable::find(sid));
    salesFormLetter.update(salesTable,systemDateGet(),SalesUpdate::All,AccountOrder::None, NoYes::No,NoYes::Yes);
    info("Sales Order Status is Delivered");

     //Post the Sales Order Invoice
    salesFormLetter=SalesFormLetter::construct(DocumentStatus::Invoice);
    salesFormLetter.update(SalesTable::find(sid));
    info(strFmt("%1 Sales Order Posted and Final Status is Invoiced",salesTable.SalesId));

}

output:


No comments:

Post a Comment

Step-by-Step Guide to Restore a SQL BACPAC File - Microsoft dynamics D365 Fin & Ops

 Restore steps for bacpac file in to SQL server - Microsoft dynamics D365 Fin & Ops. Log in to LCS and navigate to the asset library. On...