web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Dynamics 365 Community / Blogs / DAX Beginners / How to: Filter Records in a...

How to: Filter Records in a Form

Christian Silva Profile Picture Christian Silva 707

Good day Everyone,

Today I will show you how to create a query range in a form data source to filter records.
On my scenario, I have to create a form that shows basic SO informations like SalesId, Customer Account and Status and creation date. But I can’t show any SO with status Invoiced.

First, I have created a new form using SalesTable as data source and then I created a Grid to display information. It looks like this:

2014-09-15 19_05_10-Project _QueryRangeOnForm

The next step is very simple. Many query operations can be executed using the method query() of the form data source. This is done in the executeQuery() method on the form’s data source.

public void executeQuery()
{
    QueryBuildRange salesStatusQBR;
    ;

    // Creating a query range for the field Sales Status.
    salesStatusQBR = this.query().dataSourceTable(tableNum(SalesTable))
        .addRange(fieldNum(SalesTable, SalesStatus));

    // Assigning the value "!Invoiced" to show all SO NOT invoiced.
    salesStatusQBR.value(strFmt('!%1', SalesStatus::Invoiced));

    // Hiding query value from end user.
    salesStatusQBR.status(2);

    super();
}

In the code above I have created a new Range to filter the field SalesStatus from SalesTable and then I have assigned the value “!Invoiced” to show everything that does not contain Invoiced as status.
As a bonus, I have shown how to hide it from user.

This is the result:

For more information about query range expressions, I recommend to read Using Expressions in Query Ranges [AX 2012] from MSDN.


This was originally posted here.

Comments

*This post is locked for comments