Tuesday, 13 September 2016

Filter Records in a Form

How to: Filter Records in a Form

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.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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 containInvoiced as status.
As a bonus, I have shown how to hide it from user.
This is the result:
2014-09-15 19_16_27-‪Open Sales Orders‬ (‎‪2‬ - ‎‪brmf‬)‎

No comments:

Post a Comment

POSTMAN D365

  Postman is useful to test the behavior of different OData class from/to D365FO. In this post we will see the steps to setup Postman with D...