How to create sales order through code X++ in D365 AX

Hi,

How to create sales order through code X++  D365 AX

public static void main(Args _args)
{
SalesTable salesTable;
 SalesLine salesLine;
 NumberSeq numberSeq;
 SalesFormLetter salesFormLetter;
 SalesId salesId;

// Sales Table
                                            ttsBegin;
                                            //creating sales order header
                                            //getting sales order id from number sequence
                                            numberSeq = NumberSeq::newGetNum(SalesParameters::numRefSalesId());
                                            numberSeq.used();
                                            salesTable.SalesId = numberSeq.num();
                                            salesId =salesTable.SalesId;
                                            salesTable.initValue();
                                                                             
                                            salesTable.CustAccount = "US-027");
                                       
                                            salesTable.InventSiteId=Int2Str(1); ;
                                            salesTable.InventLocationId =Int2Str(11);;
                                            salesTable.initFromCustTable();
                                       
                                            salesTable.ShippingDateRequested  = salesTable.DeliveryDate;
                                            salesTable.ReceiptDateRequested =str2Date("2017-10-10",321 ); // day: 1  month: 2 year: 3
                                       
                                   
                                            //validate
                                            if (!salesTable.validateWrite())
                                            {
                                                                                       
                                                     throw Exception::Error;
                                            }
                                            salesTable.insert();
                                            ttsCommit;

//Sales Line

                                           ttsBegin;
                                            InventDim inventDim;
                                            salesline.clear();
                                            inventDim.clear();
                                            salesLine.initValue();
                                            salesLine.SalesId = salesTable.SalesId;
                                            salesLine.initFromSalesTable(salesTable);
                                            salesLine.CustomerLineNum  = "1";
                                            salesLine.ItemId ="A0001";
                                            salesLine.itemIdChanged();
                                                                                 
                                            inventDim.InventSiteId=Int2Str(1);
                                            inventDim.InventLocationId=Int2Str(11);
                                            salesLine.InventDimId=InventDim::findDim(inventDim).inventDimId ;
                                       
                                            salesLine.SalesQty= str2Num(10);
                                            salesLine.SalesUnit  ="Pcs";
                                         
                                                                             
                                            real unitPrice=str2Num(100);
                                            salesLine.SalesPrice  = unitPrice;
                                            salesLine.LineAmount = salesLine.calcLineAmount();
                                         
                                         
                                            //validate
                                            if (!salesLine.validateWrite())
                                            {
                                                throw Exception::Error;
                                            }
                                        salesLine.createLine(NoYes::Yes, // Validate
NoYes::Yes, // initFromSalesTable
NoYes::Yes, // initFromInventTable
NoYes::Yes, // calcInventQty
NoYes::Yes, // searchMarkup
NoYes::Yes); // searchPrice -- Enable this for any Trade Aggrement Prices to bring
                                            ttsCommit;


 // Confirmation
    salesFormLetter= SalesFormLetter::construct(DocumentStatus::Confirmation);
    
    salesFormLetter.update(salesTable);

}

References

http://mandruchow.blogspot.ae/2016/11/create-sales-header-create-sales-line.html
http://daxingwitheshant.blogspot.ae/2015/04/creating-sales-order-using-x-in-ax-2012.html
https://community.dynamics.com/ax/b/dynamicsaxposed/archive/2011/10/11/how-to-create-sales-order-through-code
http://daxonline.org/1463-create-salesline-from-x-code.html


Comments

  1. I would highly recommend Mr, Benjamin services to any person in need financial help and they will keep you on top of high directories for any further needs. Once again I commend yourself and your staff for extraordinary service and customer service, as this is a great asset to your company and a pleasant experience to customers such as myself. Wishing you all the best for the future.Mr, Benjamin is best way to get an easy loan,here is there email.. / 247officedept@gmail.com     Or talk to Mr Benjamin On WhatsApp Via_+1-989-394-3740 Thank You for helping me with loan once again in my sincerely heart I'm forever grateful.

    ReplyDelete

Post a Comment