How to make methods on fields disappear (aka a bug)

August 5, 2010 4 comments

Me and some of my colleagues are currently working with a customer on a Ax 2009 SP1 RU4. The other day we came to the conclusion that the modified methods on fields in a form suddenly disappeared. I know, you should write as less as possible code on a form, but sometimes there is no way around this.

After some research we found a reproduction how these methods suddenly disappeared:

  1. Go tot the AOT and chose a form
  2. Open the [FORM] -> Data Sources -> [TABLE] -> Fields -> [A FIELD] -node
  3. Add a method (for example the modified-method)
  4. Save your form
  5. Go to the properties of the table in the datasource
  6. Place your cursor in the table property (properties window)
  7. Push ENTER

The result is that the table will be reloaded in the form and all methods you created on the fields will be gone. So here you have another reason why you shouldn’t write lots of code on your forms. You can only lose it by accident.

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:

queryBuildRange.value(strFmt('((%1 == %2) || ((%1 == %3) && (%4 == "%5")))',
                    fieldStr(InventTable, ItemType),
                    fieldStr(InventTable, ProjCategoryId),

(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.

Setting propperties on a FormControl without AutoDeclaration

March 19, 2010 2 comments

When you want to set a property of a control on a form without setting the property AutoDeclaration = yes. You can address the control trough the following code, knowing that element is a FormRun-object:"btnOk").visible(false);

Catching a key-press

March 10, 2010 1 comment

When you want to catch a key-stroke on a form, you can override the method task()
The default method will look like this:

public int task(int _taskId)
    int ret;
    ret = super(_taskId);
    // write you're code here
    return ret;

Now you just need to check the _taskId, to know witch key you have stroke. You can compare this withe the values from the Task-macro.

// Task-ID values, to be used with formControl's
// return value from the method task()
// PgUp and PgDn are the numerical keyboard page up and page down commands.
// max task id

Counting the number of records in a QueryRun

March 9, 2010 No comment

When you want to count the number of records that are currently displayed on a form, and you have only one data source, just call the static method countTotal() from the SysQuery-class.

public void executeQuery()

But when you want to do the same when you joined multiple data sources, you will actually have to loop trough the whole selection. You can do this easily by calling countLoops() on the SysQuery-class. Keep in mind that this has a serious influence on your performance.

public void executeQuery()

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…)

Line Number

February 13, 2010 No comment

When you want to create a table were you want to remain the position of the records you create (like the lineNum field on the SalesLine), you just need to define a field on your new table as a ‘CounterField‘.

Step-by-step: (more…)

Lock on form elements in Dynamics Ax

November 4, 2009 No comment

Some end-users like to make their own modifications on their forms (right-click on the form –> setup). Last week I had a customer that was not able to do this trick any more. After some research and a tip from a colleague, I came to the conclusion that this had something to do with overriding the methods tabChange() and tabChanged() on the form.

Use the methods pageActivated() / allowPageDeactivate() instead.

Source / More info: