Dynamics Ax/365

How to use Model Class in Dynamics Ax/365

Hello guys,
As you know Dynamics Ax AIF services it has a complicated structure.

Sometimes we just want to export specific data.
For example, instead of fully opening CustTable, we may only want to open the fields AccountNum and AccountName.
Another reason is that if you directly open the CustTable, it will respond to you as complex XML. However, if you open it as a model, you can get the output as JSON.

In such cases, we need to create a model class. Below, I explain how to create and use this model class.

Let’s start.

1- Create new class: CustTableModel

class CustTableModel
   CustAccount accountNum;
   CustName accountName;

public CustAccount parmAccountNum(CustAccount _accountNum = accountNum)
      accountNum = _accountNum;

      return accountNum;

public CustName parmAccountName(CustName _accountName = accountName)
      accountName = _accountName;

      return accountName;

2- Create the web services and use the CustTableModel.

    AifCollectionTypeAttribute('return', Types::Class, classStr(CustTableModel))
public List getCustTables()
    CustTable      custTable;
    CustTableModel model;
    List           list = new List(Types::Class);

    while select custTable
        model = new CLSAdvanceCurrencyCodeModel();


    return list;

That’s all. Now, you can publish the services after that you can use the method.

As the number of fields in the model class increases, this task can become tiring.
That’s why I created a tool that automatically generates this model class and shared it here. Feel free to use it 🙂

I hope I have been able to help.
If you liked this article and found it helpful, please don’t hesitate to leave a comment.
If you’d like to support me and help me continue creating useful content you can buy me a coffee.

Leave a Reply

Your email address will not be published. Required fields are marked *