Thursday, June 27, 2013

In Dynamics AX 2012, we often need to post Sales Order using x++ code. It is very easy to post complete sales order using x++ code by utilizing the SalesFormLetter class. However, what if we need to post the sales order partially and not all the lines.

We have a chooseLinesQuery() method available in SalesFormLetter class that accepts a query object to post only the lines you want to post. See example below.

Tuesday, June 18, 2013

I was working with one of the AIF document services in Dynamics AX 2012. I was trying to create general journal record from .net application but I noticed that few of my field values were not getting saved in AX. AIF will not throw any error, records were getting created but few fields were missing values even I provided the values.

I was trying to set the Credit value like above but I could not. I then found that we can set the specified attribute for such fields to true and then AIF will consider to set the values for these fields. See example below.

Sunday, June 16, 2013

Dynamics AX 2012 offers different type of services that can be used to perform several operations. It is very important to understand which type of service should be used to perform your desired operation.

There are 3 types of services that are available in Microsoft Dynamics AX 2012.

Document Services

Document services are services which expose a business entity. For example, Customer, Vendor, Employee, Sales Order.

You can Map the business entity using Query and run through Document Service Wizard to build the web service and perform CRUD operations.

Custom Services

To expose a custom x++ logic.

Say, you have a custom module and you want to expose some logic/code to your custom application.

Wednesday, June 5, 2013

While performing several operations in Dynamics AX 2012. We often need to send emails to the users that includes some dynamic information that needs to be included in the email or we can say we need to generate email body on the fly. For example, if I need to send email to several worker, I would like to change the worker name for every email.

Dynamics AX 2012 offers email templates for that purpose, we can use variables in email templates and then swap their values at runtime while sending emails.

First of all, you will need to define an email template. To do this go to Organization Administration à
Setup à
Email templates.

Once the email templates form is open, create a new email template and give it a name of your choice and fill other fields like Sender email, Sender name, default language etc in both the grids. On the bottom grid, select HTML as Layout.

After the template is created, click on Email message button, this will give you an editor window where you can compose your message. See a sample message below.

Tuesday, June 4, 2013

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.

In Dynamics AX 2012, debugging AIF code requires certain operations to be performed before you can actually debug the code. Follow these simple steps to debug the AIF service code using Visual Studio

Open Visual Studio

From Application Explorer (Ctrl + D), go to classes, Open the class you want to debug, expand the methods node, right click and select "View code"

Before putting the breakpoint, Go to the Debug menu, select Attach to process, point to Ax32Serv.exe and then click Attach button.

On the status bar, you will see loading symbols...

Once all the symbols are loaded and status bar shows "Ready", put the breakpoint and run your service (either by third party app or batch job) and then you will be able to debug the code.

Also, note that while debugging the code, you will not be able to see the values for the variables by simply hovering the mouse over the variable so you need to insert the variable to the watch list either by using drag/drop or by right click and choosing add to watch.

While working with Dynamics AX 2012 AIF services. Sometimes, you need to perform some operation once all the records in the XML file are inserted in the table.

For example, let's say you call Sales order service to create 10 Sales order and passed one xml file having 10 sales orders and then you need to perform some operation like posting each sales order ONLY when all the sales order are created. To achieve this, you need to override the createList() method on Axd<Table> class and then you can perform your operations in that method by iterating all the records passed in the xml file.

To see this running, please see the AxdSalesOrder class that implements such functionality.