Thursday, 3 December 2015

Creating a custom instant search filter in X++

1. In the AOT, open the MainAccountListPage form and add a new StringEdit control
with the following properties to the existing Filter group:
Property Value
Name                        FilterName
AutoDeclaration        Yes
EDT                           AccountName
2. Override the control’s textChange() method with the following code snippet:
void textChange()
{
            super();
            MainAccount_ds.executeQuery();
}
3. On the same control, override the control’s enter() method with the following code
snippet:
void enter()
{
           super();
           this.setSelection(strLen(this.text()),strLen(this.text()));
}
4. Update the executeQuery() method of the MainAccount data source as follows:
public void executeQuery()
{
          QueryBuildRange qbrName;
          MainAccount::updateBalances();
          qbrName = SysQuery::findOrCreateRange(this.queryBuildDataSource(),fieldNum(MainAccount,Name));
         qbrName.value(FilterName.text() ?SysQuery::valueLike(queryValue(FilterName.text())) :
         SysQuery::valueUnlimited());
         super();
}
5. In order to test the search, navigate to General ledger | Common | Main accounts
and start typing into the Account name filter. Note how the account list is being

filtered automatically:


No comments:

Post a Comment