Microsoft Dynamics AX Support

This blog contains posts by the Microsoft Dynamics AX Support teams Worldwide

Calling the SalesOrderService on AX 2012

Calling the SalesOrderService on AX 2012

Rate This
  • Comments 2

Below is an example of how to create a sales order by calling the SalesOrderService create operation in AX 2012.  The example contains one sales order with 3 lines.  The code sets the financial dimensions on the sales header record and it sets an inventory dimension on the third sales line.  Happy programming!

               
SalesOrderServiceClient proxy = new SalesOrderServiceClient();

CallContext context = new CallContext();
context.Company = "ceu";

               
AxdSalesOrder salesOrder = new AxdSalesOrder();
AxdEntity_SalesTable[] salesTables = new AxdEntity_SalesTable[1];
AxdEntity_SalesTable salesTable = new AxdEntity_SalesTable();

               
salesTable.CurrencyCode = "USD";
salesTable.CustAccount = "1103";
salesTable.ReceiptDateRequested = Convert.ToDateTime("2/1/2012");
salesTable.Payment = "N060";
salesTable.PurchOrderFormNum = "PO113";

 

#region Financial Dimensions

               
AxdType_DimensionAttributeValue dimBusinessUnit = new AxdType_DimensionAttributeValue();
dimBusinessUnit.Name = "BusinessUnit";
dimBusinessUnit.Value = "20";

 

AxdType_DimensionAttributeValue dimCustomerGroup = new AxdType_DimensionAttributeValue();
dimCustomerGroup.Name = "CustomerGroup";
dimCustomerGroup.Value = "10";


AxdType_DimensionAttributeValue dimDepartment = new AxdType_DimensionAttributeValue();
dimDepartment.Name = "Department";
dimDepartment.Value = "500";

               
AxdType_DimensionAttributeValueSet valueSet = new AxdType_DimensionAttributeValueSet();

valueSet.Values = new AxdType_DimensionAttributeValue[3] { dimBusinessUnit, dimCustomerGroup, dimDepartment};
salesTable.DefaultDimension = valueSet;

#endregion 

               
AxdEntity_SalesLine salesLine = new AxdEntity_SalesLine();

salesLine.ItemId = "1000";               
salesLine.SalesQty = 1;
salesLine.SalesUnit = "ea"; 

               
AxdEntity_SalesLine salesLine2 = new AxdEntity_SalesLine();

salesLine2.ItemId = "1000";               
salesLine2.SalesQty = 55;
salesLine2.SalesUnit = "ea";

 
AxdEntity_SalesLine salesLine3 = new AxdEntity_SalesLine();
salesLine3.ItemId = "10004";
salesLine3.SalesQty = 21;
salesLine3.SalesUnit = "Pcs";

               
AxdEntity_InventDim inventDim = new AxdEntity_InventDim();               
inventDim.InventSiteId = "1";
salesLine3.InventDim = new AxdEntity_InventDim[1] { inventDim };

               
salesTable.SalesLine = new AxdEntity_SalesLine[3] { salesLine, salesLine2, salesLine3 };
salesOrder.SalesTable = new AxdEntity_SalesTable[1] { salesTable };

               
try

{

       proxy.create(context, salesOrder);                    
       Console.WriteLine("Worked");
}

               
catch (Exception e)
{

                   
       throw e; 
}

 

 

 

Leave a Comment
  • Please add 4 and 1 and type the answer here:
  • Post
  • Hi Becky,

    This is a very nice sample! Thanks. Would like to ask you one thing. If I have to import sales transactions from previous years say 2008/2009 into a new AX 2012 database, can this code be used?

    Will it show correct sales totals for previous years?

  • Hi Akash,

    You could import the transactions setting the shipping and receipt dates back to previous years but when you go to post the transactions you would still have today's date.  I don't know if you can change that date.

Page 1 of 1 (2 items)