AX 2012: crossCompany insert_recordset

Posted on Updated on

Although we cannot use crossCompany keyword with insert_recordset command, we can still achieve the same functionality with some performance overhead as follows:

static void JobCCIns(Args _args)
{
    Table21 tab21;
    Table22 tab22;

    ttsBegin;
    while select crossCompany actionDate, name, dataAreaId from tab21
        where tab21.actionDate > str2Date('1998-01-22', 321)
    {
        changeCompany(tab21.dataAreaId)
        {
            tab22 = null;
            tab22.actionDate = tab21.actionDate;
            tab22.name = tab21.name;
            tab22.insert();
        }
    }
    ttsCommit;
}

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: Change Application Object Layer

Posted on Updated on

Developers often need to change the current application object layer. For example, customizations in AX 2012 always take place in the USR layer. To change it:

1. Go to Microsoft Dynamics AX 2012 Configuration

Image

 

2. Click Manage then click Create configuration

Image

 

3. Give it a suitable name and then click OK

4. Switch to Developer tab and choose your desired layer from the drop down menu of Application object layer.

Image

 

5. Click OK

AX 2012: Reverse Engineering

Posted on Updated on

If you are working on objects (Tables or Classes) you haven’t designed then it is quite possible you could have an insight about these objects by reverse engineering them to either data model or object model. I came to know about an excellent reverse engineering tool in AX 2012, that’s why sharing here for others.

First of all create an empty project and add the tables or classes to this project you want to reverse engineer.

Untitled

Then right click the project node, click Add-Ins then click Reverse Engineer.

Untitled

Select Visio UML data model or object model depending on the elements you have added to the project (Tables or Classes). Give appropriate path to save the Visio file to.

Untitled

Reverse engineering starts. After the processing complets Visio open up automatically.

Untitled

In Visio under Model Explorer you can find your project node under Top Package. You can find your tables in the relevant table group node. AX categories each table created. The default value of table group property is “Miscellaneous”. In my case all the tables can be found under Miscellaneous node.

Untitled

Drag the tables to the drawing pane one by one and see how Visio renders table fields and relationships automatically.

Untitled

Often AX tables contain more than 100 columns which results in a tedious data model in which relationships are hard to view. To only view the relationships and hide the columns, you can suppress table columns (attributes). Right click on the table, click Shape Display Options.

Untitled

Check attributes under Suppress section to hide the attributes. In this way you can view the relationships easily!

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

AX 2012: X++ breakpoints not hitting?

Posted on Updated on

If you are not hitting the breakpoints you set in X++ code as expected then make sure that your code isn’t executed by the SysOperation Framework (formerly known as Business Operations Framework – BOF). If this is the case then you can force the AOS to debug your code in Dynamics AX Debugger by CLEARING the following check in Dynamics AX Development Workspace:

Tools >> Options >> Development >> Execute Business Operations in CIL

Moreover, make sure that Debug mode is set to:

When Breakpoint

Untitled

Actually AX 2012 executes business logic as compiled .NET CIL to run faster. You can also debug your X++ code in Visual Studio Debugger by opening your method’s xpp file in Visual Studio then attaching to Ax32.exe process (Tools >> Attach to Process). In this way you will be debugging your X++ code in compiled .NET CIL mode. You can find your method’s xpp file under the following location:

C:\Program Files\Microsoft Dynamics AX\6.3\Server\AxaptaDev\bin\XppIL\source\<TableName\ClassName>.<MethodName>.xpp

Now if your X++ code runs under SysOperations Framework, then it will be invoked by any of the following methods:

  • SysDictClass::invokeStaticMethodIL
  • SysDictTable::invokeStaticMethodIL
  • Global::runClassMethodIL
  • Global::runTableMethodIL