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:
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();
rangestr = ‘((Responsible == currentEmployeeId()) && (Responsible != ""))’;
qbds = q.addDataSource(tableNUm(ProjTable));
qr = new QueryRun(q);
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: