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.

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())));
}