1. Create Main account Extension
2. Add a group Filter, Auto dec - Yes
3. Within the group add ComboBox control FilterType, Auto decl -Yes, Selection - 10(Profit Loss), Enum Type - DimensionLedgerAccountType
4. Also Add Filter Name -> Type String, Edt - Account Name
4. Create a class extension MainAccountForm_Extension, Add below methods
[FormControlEventHandler(formControlStr(MainAccount, FilterName), FormControlEventType::Modified)]
public static void FilterName_OnModified(FormControl sender, FormControlEventArgs e)
{
FormDataSource mainAccount_ds = sender.formRun().dataSource(formdatasourcestr(MainAccount,MainAccount));
mainAccount_ds.executeQuery();
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
[FormControlEventHandler(formControlStr(MainAccount, FilterType), FormControlEventType::Modified)]
public static void FilterType_OnModified(FormControl sender, FormControlEventArgs e)
{
FormDataSource mainAccount_ds =sender.formRun().dataSource(formdatasourcestr(MainAccount,MainAccount));
mainAccount_ds.executeQuery();
}
[FormDataSourceEventHandler(formDataSourceStr(MainAccount, MainAccount), FormDataSourceEventType::QueryExecuting)]
public static void MainAccount_OnQueryExecuting(FormDataSource sender, FormDataSourceEventArgs e)
{
QueryBuildRange qbrName;
QueryBuildRange qbrType;
QueryBuildDataSource qbds = sender.query().dataSourceTable(tableNum(MainAccount));
MainAccount::updateBalances();
qbrName = SysQuery::findOrCreateRange(qbds,fieldNum(MainAccount,Name));
qbrType = SysQuery::findOrCreateRange( qbds,fieldNum(MainAccount,Type));
str filterText = sender.formRun().design().controlName("FilterName").valueStr();
if (filterText)
{
qbrName.value(SysQuery::valueLike(filterText));
}
else
{
qbrName.value(SysQuery::valueUnlimited());
}
FormComboBoxControl FilterType = sender.formRun().design().controlName("FilterType");
if (FilterType.selection() == DimensionLedgerAccountType::Blank)
{
qbrType.value(SysQuery::valueUnlimited());
}
else
{
qbrType.value(queryValue(FilterType.selection()));
}
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
[FormDataSourceEventHandler(formDataSourceStr(MainAccount, MainAccount), FormDataSourceEventType::QueryExecuted)]
public static void MainAccount_OnQueryExecuted(FormDataSource sender, FormDataSourceEventArgs e)
{
FormRun formRun = sender.formRun();
formRun.CreateTree();
}
Points to remember
a. The control should be auto declared to Yes
b. On modified should call the execute query.
c. Execute query should define the range, it should check if the range exist if not create and then apply the range.
example qbrName = SysQuery::findOrCreateRange(qbds,fieldNum(MainAccount,Name));
d. In case of text match, use qbrName.value(SysQuery::valueLike(filterText)); else make it value unlimited qbrName.value(SysQuery::valueUnlimited());