knowledgecenter-breadcrum

Knowledge Center

24 Mar, 2025

How to Dynamically Filter Subgrid Records in D365 CE

Posted on 24 Mar, 2025 by Shoaib Khan, Posted in Dataverse Power Platform

Blogs

Introduction

 

In Microsoft Dynamics 365, there are scenarios where subgrid data needs to be filtered dynamically based on user selections. This blog explains how to achieve dynamic filtering of subgrid records using JavaScript to improve data visibility and enhance user experience.

 

Use Case

Consider a scenario where a user is working on an Account form in Dynamics 365. The Contacts subgrid displays related contacts, and another subgrid should dynamically filter and display Opportunities based on the selected contact.

 

Our goal is to:

 

✅ Capture the selected contact from the subgrid.

✅ Dynamically filter the Opportunities subgrid based on the selected contact.

✅ Ensure the subgrid refreshes to reflect the applied filter.

 

Implementation: JavaScript for Subgrid Filtering

 

1. Storing the Form Context

 

When the form loads, we store the execution context globally for use across different functions

 

 

2. Handling Subgrid Selection

 

To detect when a user selects a contact in the subgrid, we add an on select event.

 

 

3. Applying the Filter to the Opportunities Subgrid

 

Dynamically construct a FetchXML query to filter the Opportunities subgrid based on the selected contact. Here, we have to use GlobalFormContext to get control of Subgrid.

 

Registering the JavaScript in Dynamics 365

 

1. Upload the JavaScript File

 

  1. Navigate to Power Apps → Solutions → Web Resources.
  2. Upload the JavaScript file and publish it.
  3. Ensure all JavaScript code is in the same web resource file.

 

2. Register the Events in the Form

 

  1. Form OnLoad Event – Register Onload on the Account form’s OnLoad event.
  2. Subgrid OnSelect Event – Register subgridOnSelect on the Contacts subgrid’s OnRecordSelect event.

 

How This Enhances User Experience

 

✅ Dynamic filtering – The Opportunities subgrid instantly updates based on the selected contact.

✅ Increased efficiency – Users no longer need to manually search for related opportunities.

✅ Seamless interaction – The subgrid updates in real-time without requiring a full-page refresh.

 

Conclusion

By leveraging JavaScript and FetchXML in Dynamics 365, we have successfully implemented dynamic subgrid filtering. This approach improves usability and ensures users see only the most relevant records, enhancing overall CRM efficiency.

If you are working with Dynamics 365 and need to optimize data visibility, implementing dynamic subgrid filtering is a powerful way to enhance your forms! smiley

Comment

This is a Required Field

Loading

Recent Updates

Blogs
01 Oct, 2026

Catch Blocks That Actually Catch: Logging Failed Steps in Power Automate

Introduction Most teams building Power Automate flows eventually land on the same pattern: wrap your business logic in a Scope,…

READ MORE
Blogs
01 Oct, 2026

Automatically Refresh a PCF Dataset Grid After Closing a Custom Page in Dynamics 365

Introduction Custom Pages provide a modern way to edit records in Dynamics 365. A common approach is to open a…

READ MORE
Blogs
23 Sep, 2026

How to Dynamically Switch Business Process Flow When Changing Forms in Dynamics 365

How to Dynamically Switch Business Process Flow When Changing Forms in Dynamics 365 Introduction Microsoft Dynamics 365 provides powerful customization…

READ MORE