Working with the Query ranges

The standard filter functionality in Ax forms is very powerful and use full way to filter records. (Cntrl + G) is the shortcut for the filter functionality. Using this filter functionality in your code is something you’ll definitely use at some point in time as a programmer.

Technically this filter functionality is called adding ranges (range = where clause of the query). This is the very details topic which includes scenarios from Simple to very advance level.

Some time you need to show filtered records on the form (adding ranges to form datasource). This is very simple, you just need write some code.


Some time you need to use expressions or if you need OR clause in the query. Support of expressions is very good to implement the complex queries containing some complex joins and conditions. if you need to implement OR clause then again you need to use the expressions. If you add ranges to two different fields then it default supports the “And &&” clause, the “OR ||” clause is only supported if you add ranges to same field with different value. In all other cases we need to use the expressions to implement the OR clause. For details on implementing the expressions

this.query().documentaries(‘InventTable’).addRange(fieldnum(InventTable,RecId)).value(strFmt(‘(ItemId == “%1”)’, queryValue(“B-R14”)));

if you need to add range on the utcdateTime field. you can add range to dateTime field, but only date value is pass to range to make it working, query will not work on time part. for details on adding the utcdateTime field as a range see below links
Complete details on utcdateTime from Ivan (Vanya) Kashperuk blog
Example from Radjip’s link:

This is another blog digging in the details of ranges.

Other than that there are two important classes in Dynamics ax 2009 which deals with the query ranges.
The SysQueryRangeUtil class is just the great enhancement to the AOT queries made in AX 2009. It is possible now to specify a range on the AOT query with the value taken from a method’s return. The requirements for such range method are quite simple: the method should be static, return string, be a member of the SysQueryRangeUtil class and not be related on the data fetched by the query
Microsoft Dynamics AX Toolbox:
MSDN Details about the class:

The SysQuery class is another useful class for working with the ranges, it has numerous method related to Query.
MSDN Details about the class:

%d bloggers like this: