Tuesday, June 4, 2013

Execute custom code when a record is inserted using AIF in AX 2012

Dynamics AX 2012 offers a very easy to use wizard to generate AIF services that can be used to perform CRUD operations from any other third party app.

We often need to perform some other operations that needs to have some business logic written to perform some operations.

For the explaination purpose, we will take the example of Sales Order.

One requirement could be to post the Sales Order automatically to AX once it is created in the system. Dynamics AX 2012 provides us the service that can create sales order. However, if you also need to post the Sales Order when it is created using AIF, you will need to write some custom code that can perform this operation for you whenever a Sales Order is created.

The method that will be called after inserting record is the updateNow() method of the Axd<Table> class and for Sales Order, it would be updateNow method of AxdSalesOrder class to perform our operation to post the Sales Order.

We can create our own method in the same class or some other helper class and then call that custom method from the updateNow method to get things done.

See the sample code:
public void updateNow()
{
    // call your custom method here
    AxdSalesOrderHelper::postSalesOrderConfirmation(salesTable);
   
}

No comments:

Post a Comment