Tuesday, November 1, 2011

How to show or hide query ranges on dialogs in Dynamics ax

Sometimes, we create dialogs which have a query associated with them. We use this query to filter records and show us some data. Often, associating such queries with dialogs adds ranges to the dialogs. But do we really need these ranges always? In this post, let us look at one of the reason why ranges may get added and how to hide them.

Let us create a simple Query as shown in the figure below. Nothing fancy about it. Just SalesTable and SalesLine joined.

Now we will create a dialog, set the dialog's query with the query we created above and run it.

When the dialog opens, this is how it looks.

Notice now that there are two SalesId ranges. These come from SalesTable and SalesLine respectively.

The logic to add the range here is that the first active index on the tables are displayed. Take a look at both SalesTable and SalesLine.

On SalesTable, the first index is SalesIdx and on SalesLine, the first index is SalesLineIdx.

Before we move further, some of you may question that SalesLineIdx has threee fields - SalesId, LineNum & RecId. So why is only SalesId shown as a range. Well, the answer is that for all child datasources, only the first range is shown.

Now back to the topic, I want to hide the SalesLine's SalesId range on the dialog. How can I do that?

The answer is to override the showIndexFields method on the dialog and return false. Let us try that.

1.public boolean showIndexFields(tableId id)
3.    boolean ret;
5.    ret = true;
7.    return ret;
Well, the fields have been hidden but the labels are still showing. This is a bug in the RunBaseDialogModify class which hasn't been fixed yet even in the latest roll up. If you are interested in fixing this, you will have to move the code on lines 26 & 27 in \Classes\RunBaseDialogModify\addQueryDatasource() inside the condition on line 75.

Coming back to our original requirement, I just want to hide the range for the SalesLine table. If you look closely at the showIndexFields() method's signature, it passes a tableId value. We can use this value to decide which tables to show the ranges for and which to disallow.

01.public boolean showIndexFields(tableId id)
03.    boolean ret = true;
05.    switch(id)
06.    {
07.        case tableNum(SalesLine):
08.            ret = false;
09.            break;
10.    }
12.    return ret;

As you can see from the below image now, only the range on SalesTable is visible now. The SalesLine range's label is still visible which is due to the bug in code I mentioned above.

In this post, we learnt how we can hide the ranges of certain tables by overriding the showIndexFields() methods.

You can download the project I have used in this post from here

No comments:

Post a Comment