Using Methods Inside Query Range

This article may be a little late. I had discovered this long time back for one of the usages but writing it down now.

In class SysQueryRangeUtil you will find many static methods that can be used in a Range of a query.

Following are the methods that be used:

  • currentBusinessRelationsAccount
  • currentContactPersonId
  • currentCustomerAccount
  • currentEmployeeId
  • currentSessionDate
  • currentSessionDateTime
  • currentStaticMasterPlan
  • currentUserId
  • currentVendorAccount
  • dateRange
  • day
  • dayRange
  • greaterThanDate
  • lessThanDate
  • monthRange
  • yearRange

It is often useful to have these methods specially the methods involving dates. Think you have to set up a recurring batch job where you need to filter some records based on date criteria say all transactions having transactions today – 10. During such times these methods can be useful.

Here is one such example:

static void methodsInsideQueryRange(Args _args)
    Query                   q = new Query();
    QueryRun                qr;
    QueryBuildDataSource    qbds;
    str     rangestr;
    ProjTable   p;

    rangestr = ‘((Responsible == currentEmployeeId()) && (Responsible != ""))’;
    qbds = q.addDataSource(tableNUm(ProjTable));
    qbds.addRange(fieldNum(ProjTable, Responsible)).value(rangestr);

    qr = new QueryRun(q);
    while (
        p = qr.getNo(1);


This is how you use them in code. Now how is it useful in daily tasks?

Think of a scenario where you have 100’s of transactions posted daily and say you want to filter out those transactions that have been posted in last two months? How will you filter them?

Take all the transactions to excel and filter there?

Hold on there is a better way to do it in AX 2009.

On the required form press Ctrl + G and then in the filter use these methods:

Ex: (monthRange(-2,0)). This means we need to filter all those transactions starting from 2 months behind and till today. If we specify (monthRange(-2,2)), this means all the transactions between 2 months backward and 2 months forward.

Check  the screen shots below:

Here is a screen shot of Item transactions form before applying monthRange:


After we apply the monthRange method filter:



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s