Tuesday, 5 August 2025

How to Disable “Advanced Filter or Sort” and Enforce Custom Filters on Any D365FO Form

 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;

    }

}


No comments:

How to Disable “Advanced Filter or Sort” and Enforce Custom Filters on Any D365FO Form

 In Dynamics 365 Finance and Operations, users can apply filters through the “Advanced filter or sort” feature found under the Options tab...