Hi All
I have a requirement in D365FO to filter the form data based on a condition on one of the joined datasource. Here in this case I took a checkbox (yes/No) to filter the data.
when the checkbox is yes then data needs to be filtered by specific range on joined datasource. When the checkbox is made "NO" then entire data of Main datasource needs to be displayed.
Here the challenge seems to be due to the even handlers I took instead of chain of commands in D365 FO form.
the issue is when we first filter the data by clicking the checkbox "Yes" then formdatasource query has the llinked datasource that are added using query build framework, range is perfectly set and filter is happening correctly. But when we make the checkbox "NO", the querybuildDatasource of main table still has the linked datasource Range that was set previously even though we clear the range (using clearrange() or clearRanges()). Instead of clearing the ranges, the datasources are getting added to the query when we clcik multiple times Yes/No...
Please look at the below code and let me know if I can make some changes to remove the range or clear the range when we make the checkbox NO.
[FormControlEventHandler(formControlStr(XYZFashionStoreItems, FashionItemsCheckBox), FormControlEventType::Modified)]
public static void FashionItemsCheckBox_OnModified(FormControl sender, FormControlEventArgs e)
{
FormDataSource inventTable_ds;
QueryBuildDataSource qbdsInventTable;
QueryBuildDataSource qbdsDimensionAttributeValueSet;
QueryBuildDataSource qbdsDimensionAttributeValueSetItem;
FormCheckBoxControl fashionItemsCheckBox = sender.formRun().design(0).controlName("FashionItemsCheckBox") as FormCheckBoxControl;
Query query;
QueryRun queryRun;
inventTable_ds = sender.formRun().dataSource(formDataSourceStr(XYZFashionStoreItems, InventTable));
qbdsInventTable = inventTable_ds.queryBuildDataSource();
qbdsDimensionAttributeValueSet = qbdsInventTable.addDataSource(tableNum(DimensionAttributeValueSet));
qbdsDimensionAttributeValueSet.relations(true);
qbdsDimensionAttributeValueSet.joinMode(JoinMode::ExistsJoin);
qbdsDimensionAttributeValueSetItem = qbdsDimensionAttributeValueSet.addDataSource(tableNum(DimensionAttributeValueSetItem));
qbdsDimensionAttributeValueSetItem.relations(true);
qbdsDimensionAttributeValueSetItem.joinMode(JoinMode::ExistsJoin);
if (fashionItemsCheckBox.value() == NoYes::Yes)
{
qbdsDimensionAttributeValueSetItem.addRange(fieldNum(DimensionAttributeValueSetItem, DisplayValue)).value('09');
}
else
{
qbdsDimensionAttributeValueSetItem.sortClear();
qbdsDimensionAttributeValueSetItem.clearRange(fieldNum(DimensionAttributeValueSetItem, DisplayValue));
qbdsInventTable.clearDynalinks();
qbdsInventTable.clearLinks();
qbdsInventTable.clearRanges();
}
inventTable_ds.executeQuery();