Search This Blog

Wednesday, August 24, 2011

How to use Query Ranges with Expressions

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.

this.query().dataSourceName(‘CustTable’).addRange(fieldnum(CustTable,Custgroup)).value(queryvalue(‘20));

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″))); http://www.axaptapedia.com/Expressions_in_query_ranges

Other than that there are two important classes in Dynamics ax 2009 which deals with the query ranges.

SysQueryRangeUtil
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

No comments:

Post a Comment

Thanks for visiting my blog,
I will reply for your comment within 48 hours.

Thanks,
krishna.