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.

21 Comments

  1. I attempted to use your code here but I noticed that my AxdEntity_SalesTable does not have the .ReceiptDateRequested property… Any ideas?

  2. 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.

  3. I need to post a sales order using formletterservice using c# code.Is there any links or information available on this?

  4. 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.

  5. 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.

  6. 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.

  7. Hi martin

    can u please providde the steps with which i can create sales order using AIF web service in ax 2012.

    • 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.

  8. I dont have class AxdEntity_SalesTable at all… I need to use some creator to generate it ?? And where can i find information which reference contain which classes and fields ?? And 🙂 Is there any place in AX qhere can i find all references ??

    • The classes are generated when you add the service reference to your Visual Studio project, therefore if you want to see all classes and fields, simply look at the generated code (enable “Show All Files” and look at files included inside the service reference node). Nevertheless IntelliSense usually tells you all what you need.

      Note that the classes are not created in the same way in all cases. It depends on whether you enabled data policies or not (I think this is your case), which fields you enable and which options you use when adding the service reference. That’s why there can’t be one single documentation (even if we ignore customizations) and why you can’t expect all code you find to work with your particular proxy classes.

  9. i am getting error in this line : client.create(callContext, orderList); error is SalesOrder.SalesOrder.AxdSalesOrder Has some invalid arguments. please help me to find solution new to dynamics ax.

    • Are you sure it’s the exact error message? What kind of error it is?
      Let me guess: you get a compilation error which actually says that the expected second argument is an object of AxdSalesOrder, instead of an array of AxdEntity_SalesTable objects that you’re currently passing there. Then the solution should be completely obvious: create and use an instance of AxdSalesOrder instead of the array.
      Whether the proxy is generated this way or that way depends on how you inbound port is configured.

  10. thank you sir, it is from inbound port. Now problem from credential how i can pass the credentials.

    • I’m sorry, but I can’t help you if you don’t give me enough details about your problem. Also, I strongly recommend you use discussion forums to discuss things like this – you’ll reach many more people there and forums are better suited for dealing with a lot of text, source code, images and so on. I personally contribute to community.dynamics.com and dynamicsuser.net.

  11. I’m sorry, I have a (dumb) question. Using this rutine Is it possible to assign a personalized value to the Sales order number field? Or AX don’t allow to assign that specific field.

    • I think it should work out of the box, if you configure the number sequence as manual. If not, please provide details about the observed behavior.
      Note that a discussion forum would likely be a better place for the discussion. If nothing else, there are many more people who can answer your questions.

Comments are closed.