Microsoft Dynamics 365 Blog

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; 
}

 

 

 

We're always looking for feedback and would like to hear from you. Please head to the Dynamics 365 Community to start a discussion, ask questions, and tell us what you think!