In Dynamics 365 Finance and Operations, users can apply filters through the “Advanced filter or sort” feature found under the Options tab. But sometimes, you want to:
-
Prevent users from modifying queries manually
-
Enforce organization-specific filtering logic (e.g., based on dimensions, roles, or personnel)
This post explains how to do that generically, so you can reuse this logic for any form or datasource.
✅ What We'll Do
-
๐ Disable "Advanced filter or sort" and shortcut filters
-
๐งน Clear user-applied filters
-
๐ฏ Apply organization-controlled filters
-
๐งผ Use a clean helper + event-handler pattern
๐งฉ Step 1: Disable “Advanced Filter or Sort” in the Form
Extend the form and override the task()
method to block the SysQuery task:
Generic Form Extension Example:
[ExtensionOf(formStr(PurchTable))]
final class MKPurchTableForm_Extension
{
public int task(int _taskId)
{
#Task
FormRun formRun = this as FormRun;
FormDataSource purchTable_ds = formRun.dataSource(formDataSourceStr(PurchTable, PurchTable)) as FormDataSource;
// Always call next task() first (per best practices)
int ret = next task(_taskId);
// Only act if it's a filter task
if (_taskId == #taskFilter || _taskId == #taskShortCutMenuFilter)
{
info("Advanced filtering is disabled.");
if (purchTable_ds)
{
POAccessHelper::applyPOAccessFilter(purchTable_ds);
purchTable_ds.executeQuery(); // Re-run query with our custom filters
}
// Override the result to suppress filter behavior
ret = 0;
}
return ret;
}
}