Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Sales Order creation using classes and class declaration in ax 2012

(0) ShareShare
ReportReport
Posted on by

Sir how can we create sales order in AX 2012 using classes and class declaration,using different classes related to sales order.

*This post is locked for comments

  • Community Member Profile Picture
    on at
    RE: Sales Order creation using classes and class declaration in ax 2012

    I need such a code that are using the ax classes to create a sales order,This code is asking for (literator.more()) but I don't know what is the type of literator they ask for declaration.I was using my own aurguments and giving static  value in place of  _SOContract.custAccount().

    private SalesId createAXSO(AMSSalesOrderContract _SOContract)
    {

       SalesTable salesTable;
    SalesLine salesLine;

    AxSalesTable axsalesTable;
    AxSalesLine axSalesLine;
    SalesFormLetter salesFormLetter;
    ;
        //Create Sales order
        custTable = CustTable::find( _SOContract.custAccount());
        salesTable.initFromCustTable();

        axsalesTable = AxSalesTable::newSalesTable(salesTable);
        axsalesTable.parmCustAccount( _SOContract.custAccount());
        axsalesTable.parmSalesType(SalesType::Sales);

        axsalesTable.parmDocumentStatus(DocumentStatus::Confirmation);

        axsalesTable.parmDeliveryDate(systemDateGet()+ 30);
        axsalesTable.parmSalesStatus(SalesStatus::Backorder);

        axsalesTable.doSave();
        while (literator.more())
        {
                lSalesLineContract = literator.value();
                salesLine.initFromSalesTable(salesTable);

                axSalesLine = AxSalesLine::newSalesLine(salesLine);
                axSalesLine.parmItemId(lSalesLineContract.itemId());
                 //////Mandatory Values
                inventDim.InventSiteId = "AUS";
                inventDim.InventLocationId = "EPH";
                inventDim = InventDim::findOrCreate(inventDim);

                axSalesLine.parmInventDimId(inventDim.inventDimId);
                axSalesLine.parmCurrencyCode("AUD");
                axSalesLine.parmSalesQty(4);
                axSalesLine.parmSalesPrice(20.00);
                axSalesLine.doSave();
            literator.next();
        }

        //SO confirmation
        salesTable = axSalesTable.salesTable(salesTable);
        salesFormLetter = SalesFormLetter::construct(DocumentStatus::Confirmation);
        salesFormLetter.update(salesTable);
    // SO invoicing
    salesFormLetter = salesFormLetter::construct(DocumentStatus::Invoice);
    salesFormLetter.update(salesTable);
        return salesTable.SalesId;
    }

  • Blue Wang Profile Picture
    on at
    RE: Sales Order creation using classes and class declaration in ax 2012

    Hi Jamil,

    Here’s the code you can use to create a sales order in Dynamics AX 2012 through X++.

    static void CreateSalesOrder(Args _args)
    
    {
    
    //declaring variables
    
    SalesTable salesTable;
    
    SalesLine salesLine;
    
    NumberSeq numberSeq;
    
    SalesFormLetter salesFormLetter;;
    
    ttsBegin;
    
    //creating sales order header
    
    //getting sales order id from number sequence
    
    numberSeq = NumberSeq::newGetNum(SalesParameters::numRefSalesId());
    
    numberSeq.used();
    
    salesTable.SalesId = numberSeq.num();
    
    salesTable.initValue();
    
    salesTable.CustAccount = ‘US-001’;
    
    salesTable.initFromCustTable();
    
    //validate
    
    if (!salesTable.validateWrite()) {
    
    throw Exception::Error;
    
    }
    
    salesTable.insert();
    
    //creating sales order line
    
    salesLine.SalesId = salesTable.SalesId;
    
    salesLine.ItemId = ‘D0001’;
    
    salesLine.SalesQty = 2;
    
    salesLine.LinePercent = 1;
    
    salesLine.createLine(true, // Validate
    
    true, // initFromSalesTable
    
    true, // initFromInventTable
    
    true, // calcInventQty
    
    true, // searchMarkup
    
    true  // searchPrice
    
    );
    
    ttsCommit;
    
    //confirm sales order
    
    salesFormLetter = SalesFormLetter::construct(DocumentStatus::Confirmation);
    
    salesFormLetter.update(salesTable);
    
    //displaying sales order id
    
    info(salesTable.SalesId);
    
    }

    Best Regards,

    Blue Wang

  • Suggested answer
    Sukrut Parab Profile Picture
    71,682 Moderator on at
    RE: Sales Order creation using classes and class declaration in ax 2012

    You can refer below code . If you know how to create classes (which you can easily search on the web ),you can utilize below code

    community.dynamics.com/.../how-to-create-sales-order-through-code

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,424 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 233,043 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans