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:

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.

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:

element.design().controlName("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()
//--------------------------------------------------------
 
#define.taskF1(257)
#define.taskCtrlQ(264)
#define.taskEnter(288)
#define.taskShiftEnter(307)
#define.taskNew(260)
#define.taskSave(272)
 
#define.taskShortCutMenuKey(519)
#define.taskAlt(520)
 
#define.taskCut(770)
#define.taskCopy(771)
#define.taskPaste(772)
 
#define.taskDeleteKey(773)
#define.taskSelectAll(778)
 
#define.taskUndo(769)
#define.taskRedo(791)
 
#define.taskArrowUp(1281)
#define.taskArrowDown(1282)
#define.taskArrowLeft(1283)
#define.taskArrowRight(1284)
 
// PgUp and PgDn are the numerical keyboard page up and page down commands.
#define.taskPgUp(1285)
#define.taskPgDn(1286)
 
#define.taskEsc(1313)
 
#define.taskNextRecord(2817)
#define.taskPrevRecord(2818)
 
#define.taskDeleteRecord(2832)
 
#define.taskPageDown(2819)
#define.taskPageUp(2820)
 
#define.taskTab(2827)
#define.taskNext(2827)
#define.taskPrev(2828)
 
#define.taskShortCutMenuFilter(2844)
#define.taskShortCutMenuFind(799)
#define.taskFilter(2837)
 
// max task id
#define.taskLast(8191)

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()
{
    ;
    super();
    info(int2str(SysQuery::countTotal(EmplTable_ds.queryRun())));
}

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()
{
    ;
    super();
    info(int2str(SysQuery::countLoops(EmplTable_ds.queryRun())));
}

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.

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

Source / More info:
http://dynamics-ax.blogspot.com/2007/06/yellow-lock-in-dynamics-ax-401.html