All posts by Admin

Problem with str2enum

Just found a strange behaviour in using the standard str2enum function. Consider the following code ;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
static void TestOfEnumsWithFirstValueBlank(Args _args)
{
    ProjCategoryType selectedType;
    str              s;
    ;
 
    selectedType = ProjCategoryType::None;
    s = enum2str(selectedType); // get enum string
    print s; // shows nothing, since None has no label.
 
    selectedType = str2enum(selectedType,s); // convert back
 
    if(selectedType == ProjCategoryType::None)
        print "'None' selected";
    else
        print "undefined..."; // sadly this is printed..
 
    pause;
}

This example code prints undefined, NOT ‘None’ selected. This because str2enum does not handle an empty string in a correct way, even if one of the values in the choosen enum has the emptry string as it’s label. This means values to str2enum must always be validated first before each call..

AIF – Wrong field ID in the key data container in entity key

@SYS92355 = “Wrong field ID in the key data container in entity key”

This error message from the AIF in AX4sp2 did give me some headache today..

Finally I solved it. I was about to export a SalesOrder with both header and lines, but I did put my sendElectronically method in the SalesLine table, *not* in SalesTable table.. So when executed I never got the correct keys. The query I used for the axd wizard was based on SalesTable first, and THEN SalesLine..

Might help someone else with the same or similar problem!

How to colour code different companies inside axapta

During development and test we often switch between different companies in our installation. To not mistaken us, so we always make changes in the correct one, we made this small change in the code. With different background-colours for each company, you never delete something importent by mistake. This example shows how it could be done.
Continue reading How to colour code different companies inside axapta

How to catch special keystrokes and use them as shortcuts

Rightclick on a form and go down tracking a specific field or other data, is a tedious work if you do it dozens of times per day.

We wanted to catch the key combination ctrl+Z (since it is rarelly used when running axapta), so we could use it to display common data about a form, field or other info. This is a code example we nowdays always install in all new test and development environments (not production, since it would give normal users unwanted access).
Continue reading How to catch special keystrokes and use them as shortcuts

How to clock routines which (should) go faster than 1 sec

From the basic routines in Axapta we only have the TimeNow() function which returns number of seconds since midnight. To measure something more exact than that, we either need to do an API call to getTickCount or to use the setTimeOut() function. This is a small demo on how to implement both such timers.
Continue reading How to clock routines which (should) go faster than 1 sec

Strange behaviour when calling form

I was building an extended search form for one of our customers. When called from one form everything worked fine, but when called from a second form my grid only contained one record… Exact same parameters, same menu item etc. When looking around I found that when the error occured, I was calling from a form which had same table (InventTable) as one of it’s main Data Sources. This is one of the non-documented features in AX, if same table exists in the Data Sources in both forms, AX tryes to link them together. To break this connection I had to call ClearDynaLinks() on the second form. Like below, in my search form’s init method.

1
2
3
4
5
6
7
8
9
void init() 
{
 
    ....
 
    InventTable_ds.query().dataSourceTable(
                 tablenum(InventTable)).clearDynalinks();
 
}