Tables

AX 2012: Display methods – Different datasources – Same control

Posted on Updated on

AX developers always come across a requirement of showing data from different datasources on the same control though these datasources should be related to each other. The solution to this requirement is to define display methods on the table which you choose to be the control datasource. Display methods are very handy for showing data from related tables.

Consider for example the following tables:

1. CustTable
2. DirPartyTable
3. BankGroup

If we need to show CustTable.AccountNum, DirPartyTable.Name and BankGroup.Name fields on the same control let’s say a grid control then we need to define the following display methods on CustTable if we have chosen CustTable as the grid’s datasource.

To retrieve DirPartyTable.Name

Untitled

To retrieve BankGroup.Name

Untitled

Now on the grid control, add  two StringEdit controls to bind them with the display methods just defined above. Make sure to specify CustTable as the grid’s datasource. Also you must be setting DataMethod property of the StringEdit controls to the name of the respective display methods.

Untitled

The result is awesome. You have one grid control showing data from different datasources!

Untitled

AX 2012: Generate next number sequence in X++

Posted on Updated on

Often we do not need to generate the next number sequence manually in X++ since creating records by using forms the system automatically handles number sequence generation by invoking Number Sequence Framework.

However, sometimes we need to generate number sequences manually in X++. The following code helps you to do that:

static void numberSequence(Args _args)
{
    NumberSeq             numberSeq;
    SMAServiceObjectTable serviceObjectTable;

    numberSeq = NumberSeq::newGetNum(SMAParameters::numRefSMAServiceObjectId());

    serviceObjectTable.clear();
    serviceObjectTable.ServiceObjectId = numberSeq.num();
    serviceObjectTable.insert();

    numberSeq.used();
}

NumberSeq is the class in action here. Its static method newGetNum() takes NumberSequenceReference as an input parameter. All you need to do is to find the relevant number sequence reference in your case. Usually there are parm methods defined on Tables which give you the number sequence references.

AX 2012: Conditional Relations with Field Fixed and Related Field Fixed

Posted on Updated on

Conditional relations are used to filter records in parent or related table. We can define conditional relations by specifying fields in a table relation as:

  • Field Fixed    OR
  • Related Field Fixed

Consider a scenario of a call center. The operator’s responsibility is to receive calls and get the orders for a shoe store. The operator first has to determine whether the order is of men’s, women’s or kid’s collection. Once the collection is determined then the operator has to determine which particular shoes the customer is ordering. It would be easier for the operator if the system filters shoes records based on the collection type [Men, Women, Kids]. In this situation conditional relations using a Field Fixed method fits the solution.

First, we will be creating two base enums such that CollectionType is like [Men(0), Women(1), Kids(2)]:

Untitled

Then we will be creating three tables respectively for Men’s, Women’s and Kids’ collection. Note that all the three tables share the same set of fields:

Untitled

Then we will be creating the final table for storing Orders. Two important fields must be added to the orders table in order to get benefit from conditional relations:

  1. ArticleCode                – To lookup records into three different collection tables
  2. CollectionTypeId    – To distinguish table relations defined for the collection tables

Untitled

You can see in the picture how three relations have been defined. Each relation contains two fields, one used for determining the collection type and the other mapping to the respective collection’s Article Code field. Once all this is done, then now the system filters records for the user depending on the collection type the user has selected. See below how the system shows records from the men’s collection when CollectionType is set to ‘Men’:

Untitled

Below is an example of CollectionType set to ‘Women’:

Untitled

Below is an example of CollectionType set to ‘Kids’:

Untitled