Change the language at runtime

November 30, 2011 No comment

Normally when you change your language you go to your user options, change your current language and the restart the client. This week I got the question if it was possible to do so in runtime. You can do so by just calling the infolog.language(str 7 _languageCode). All labels that you load after calling this method will be translated to the new language. (more…)

Amount in words

November 28, 2011 No comment

This week one of my customers asked me to place the amount in words on a invoice. I couldn’t believe that sush function wasn’t availible in standard Ax. After some research I found that the Global-class contains the following methods:

(more…)

Records with RecId 101090

August 4, 2010 2 comments

I was using the postload method of the HRMBenefitType-table to fill the description-field with language-sensitive description (from LanguageTxt). This works fine when I view the record, but not when I use a lookup.

I’ve put a break-point on my postload method and noticed the recId (this.recid of the HRMBenefitType table). This is always the 101090. When I check this in the tablebrowser, this does not match the actual RecId valule.
I checked the SQL-trace-log and noticed the following instruction:

SELECT A.HRMBENEFITTYPEID,A.DESCRIPTION,A.RECVERSION,101090 FROM HRMBENEFITTYPE A WHERE (DATAAREAID=?) ORDER BY A.DATAAREAID,A.HRMBENEFITTYPEID OPTION(FAST 1)

The solution to this problem is simple. Just change the CacheLookup property to EntireTable and the strange behaviour of the RecId-field stops.

System tables – part1

May 3, 2010 No comment

In this post I will talk about some Ax kernel tables that are automatically created after the setup at the first run of Ax. They are typically company independent (no DataAreaId) and contain some valuable information about AX.

You can find the tables I wil discuss under the AOT –> System Documentation –> Tables.

It is not easy to find info about these tables, but I hop this helps you all a bit.

Batch job performance boost

April 22, 2010 No comment

Did you ever have trouble with the performance of your batch-job? Well maybe this small trick can shorten the time your batch runs.

The big idea: Try to split up your gigantic batch in smaller pieces. Launch a batchjob that produces many smaller batchjobs (tasks) that can handle a subset of the data you need to process. For example you can create a batch that creates a batch with sub-tasks for each company.

How do you plan a batch from code?

1
2
3
4
5
6
7
8
9
10
11
12
BatchHeader batHeader;
BatchInfo batInfo;
TstRunBase rbbTask;
;
rbbTask = TstMyBatch::construct();
batInfo = rbbTask.batchInfo();
batInfo.parmCaption("MyBatch");
batInfo.parmGroupId("");
batHeader = BatchHeader::construct();
batHeader.addTask(rbbTask);
batHeader.save();
info(batInfo.parmCaption());

You can download a quick example I made. This is a job you can schedule and it will produce a new Batch job with a task for each company when you don’t select a company while shedualing (Class_TstRunBase.xpo). I hope this can help you.

Schedule the batch:

The result:

Expressions in query ranges – limitations

April 9, 2010 2 comments

When you want to construct a query-object that contains OR-conditions, you can construct something like this:

1
2
3
4
5
6
queryBuildRange.value(strFmt('((%1 == %2) || ((%1 == %3) && (%4 == "%5")))',
                    fieldStr(InventTable, ItemType),
                    any2int(ItemType::Service),
                    any2int(ItemType::Item),
                    fieldStr(InventTable, ProjCategoryId),
                    queryValue("Spares")));

(you can find more info on Axaptapedia: Expressions in query ranges)

Now there is a limitation to this way of working. When the generated string in the queryBuildRange.value is longer than 250 characters (the length of the range EDT), Ax cuts the generated string off when you open the ‘modify query’ dialog. I have tried to enlarging the EDT, but is not a good solution. The error does not occure when you open the ‘modify query’ dialog, but it occures when you close it.
A small (but limited) work-around could be to make the name of the datasources on the form/report where you want to apply this trick smaller. I hope to find a better solution, but this does the trick for now.

Test if a configuration key is enabled in X++ code

March 22, 2010 No comment

How do you execute code when a Configuration key is enabled?
It is pritty easy. Ax x++ has a build-in function ‘isConfigurationKeyEnabled’, witch you can use to check a configuration key.

Small example:

if (isConfigurationKeyEnabled(configurationkeynum(AIF)))
{
    // Do something...
}

List of mandatory fields on a table

February 22, 2010 No comment

When you want a list of all the mandatory field on table X, yould check all the properties on the table fields, or you could be lazy and write a small job that does the trick for you. Just replace TableId with your tablenum.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
static void CheckMandatoryFieldsOnTable(Args _args)
{
    DictTable dictTable;
    DictField dictField;
    int i;
    TableId tableId = tablenum(custtable);
    ;
    dictTable = new DictTable(tableId);
    for (i=1 ; i<=dictTable.fieldCnt() ; i++)
    {
        dictField = new DictField(tableId, dictTable.fieldCnt2Id(i));
        if (dictField.mandatory())
        {
            info(dictField.name());
        }
    }
}

Code Editor – shortcuts

February 20, 2010 No comment

Underneed you find the list of shortcuts I use most in Microsoft Dynamics Ax while developing.

And there are more shortcuts. You can find them on MSDN.

Working with numbersequences – On forms

February 18, 2010 No comment

When you want to implement NumberSequences in a Ax form (new numbersequence when you create a record etc.) you can just implement the ‘numberSeqFormHandler’.

Step-by-step: (more…)

Next Page »