About Me

Monday, December 20, 2010

Filter datasources of same table on Tab Pages

I had a requirement to show the filtered data of one table on different tabs within a form. The standard filter functionality in AX forms is a powerful feature. Using this filter functionality in your code is something you'll definitely use at some point in time as a programmer.

Let me explain it with an example; we have a currency table with multiple currencies e.g. EUR and USD. I have two different tabs named ‘EUR’ and ‘USD’ and these will show the respective filtered data from the currency table i.e. EUR tab will show the EUR currency and USD will show the USD currency data.

Add two datasources (CurrencyEUR and CurrencyUSD) on the form of the same table (Currency), after assigning these datasources to the tabpages. You just need to follow the following 3 steps.

Step 3: In the last step, you assign a value to the range.This is done in the executeQuery method on the same datasource of the form. Before the super call. Like this:

DataSource: CurrencyEURpublic void executeQuery(){ ;

CurrencyQBREUR.value(queryvalue('EUR'));

super();}

DataSource: CurrencyUSDpublic void executeQuery(){ ;

CurrencyQBRUSD.value(queryvalue('USD'));

super();}

This can be done in one line of code as well. In the init() method of the form datasource, after the super call, place this code:this.query().dataSourceName(‘Currency’).addRange(fieldnum(‘Currency’,CurrencyCode)).value(queryvalue('USD'));

But this way, it's fixed. If you choose the 3 step method, you could for example use a variable in the range value. The way to go would be to place an input field on your form. Get the value from it and supply it in the executeQuery() method.