Skip to content
 

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.

3 Comments

  1. Bob says:

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

  2. Martin Dráb says:

    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. Divya says:

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

Leave a Reply