Business requirement: Adding a custom filter to a form
In some cases it is required to ease the filtering on a form. In some cases end users don’t have enough Dynamics AX knowledge to use the Advanced Filter Sort functionality to create a query on the form to achive their filtering requirements.
Solution: Add a checkbox custom filter
The solution is elaborated by means of an example. Suppose you want to provide the end user with an easy filtering on the customer form to show only customers with active Projects (Projects not in the Project Stage Completed).
To achive this, you can follow these steps:
- Duplicate the CustTable form and add a checkbox control ctrlCustActProjs to it for the filtering purposes. Set the AutoDeclaration property of the checkbox to Yes.
- Add the ProjTable data source to the form and link it to the CustTable data source.
- Override the executeQuery method of the CustTable data source as follows:
public void executeQuery()
{
QueryBuildDataSource qbdsProjTable =
this.query().dataSourceTable(tableNum(ProjTable));
QueryBuildRange qbrProjStatus;
;
if (ctrlCustActProjs.value() == NoYes::Yes)
{
qbdsProjTable.enabled(true);
qbrProjStatus =
SysQuery::findOrCreateRange(qbdsProjTable,
fieldnum(ProjTable, Status));
qbrProjStatus.value(
Global::queryNotValue(
ProjStatus::Completed));
}
else
{
qbdsProjTable.enabled(false);
}
super();
}
By toggling the checkbox only customers with active Projects will be shown or not.
Enabling the qbdsProjTable QueryBuildDataSource based on the checkbox links or removes the ProjTable to the CustTable in the form query.
The search for only active Projects is achieved by adding or finding the qbrProjStatus QueryBuildRange. Use the Global::queryNotValue to look up values different from a base Enum value.
Post a Comment