Creating sales orders via AIF in AX2012

I was asked for an example how to create a sales order through AIF document services (SalesSalesOrderService). Here is my minimalist variant in C# (for AX2012 and demo data):

var line = new AxdEntity_SalesLine()
{
    ItemId = "D0001",
    SalesQty = 42,
    SalesUnit = "ea"
};
 
var order = new AxdEntity_SalesTable()
{
    CustAccount = "US-003",
    PurchOrderFormNum = "xyz",
    ReceiptDateRequested = DateTime.Now.Date,
    SalesLine = new AxdEntity_SalesLine[] { line }
};
 
var orderList   = new AxdEntity_SalesTable[] { order };
var callContext = new CallContext() { Company = "USMF" };
var client      = new SalesOrderServiceClient();
 
try
{
    client.create(callContext, orderList);
    client.Close();
}
catch
{
    client.Abort();
    throw;
}

It doesn’t have to work for you out of the box (for example, you may have additional fields required by the contract), but it should give you an idea how it looks like, without adding unnecessary complexity.

If you’re not familiar with AIF document services, you may want to look at AX 2012 Documentation Resources for AIF and Services.

12 Comments

  1. In general, the schema is not fixed. You can go and enable or disable some fields or even change the code of the document service.
    In my AX application (AX 2012 R2 CU7 without customizations), ReceiptDateRequested is set as mandatory in AxdSalesOrder.initMandatoryFieldsMap(), therefore it’s required by default. You have something different in your application.

  2. Hi Martin,
    How can I include the address information? I have to include the existing address information which is available on the sales order creation form (Not to give the new address). I have to use the address which is allocated for that customer.

  3. Suresh, I don’t know what you mean by “Document service order is not created”. I suggest you explain your problem on one of two discussions forum where I’m present: community.dynamics.com or dynamicsuser.net.

  4. Hi ,
    In my AX application (AX 2012 R2 CU7 without customization) .I want to create Inbound Port for Sale order.Tab Service contract customization click on Service Operations after open pop windows the Remaining Service Operation list box there are not found “salessalesorderservice.Create” ????
    Please help me why these service is not found.
    Windows has been updated and i have login as Contoso\administrator privilege.

    How can found these service in service operation List Box ?

    • What do you see there, then? By the way, a discussion forum may be a better place for this discussion. I’m there (community.dynamics.com and dynamicsuser.net) anyway, there are many more people who can help you, you can attach images there and so on.

    • Do you mean more detailed steps than in this blog post? It’s intentionally simple – the point of this post is to show the absolute minimum; details can be found in documentation.

Leave a Reply

Your email address will not be published.