Showing results for 
Search instead for 
Did you mean: 

Binding FetchXML to Subgrid with reference to RecordID to filter Subgrid dynamically

Subgrids are great but the limitation of needing a direct relationship between the sub entity and the main entity makes it very restrictive. There are many different use cases, if instead of using a pre-configured view that only allows linking to the active Record via a predefined relationship, we could instead bind a custom FetchXML do a subgrid and this custom FetchXML would allow for one token called #RecordID# to reference the currently open record on the form by returning the GUID. 


Use Cases of Subgrids that could be placed on an account if we could filter based on the active record: 

  •  fully support subgrids that include records down the hierarchy
    • e.g. show opportunities of this account and all accounts lower in the hierarchy
      (Opportunities WHERE AccountID = #RecordID# OR AccountID.AccountID UNDER #RecordID#)
  • fully support subgrids showing data that is connected via multiple relationships 
    • e.g. show all orders that have the AccountID of the active record in Ship To Account OR Bill To Account
      (Orders WHERE BillToAccount = #RecordID# OR ShipToAccount = #RecordID#

  • fully support subgrids going down 2 or 3 or n levels instead of just the one direct level possible out of the box
    • e.g. show all event registrations off Contacts at this Account
      (Event Registrations WHERE Contact.ParentAccount = #RecordID#)


Please either make this available as

  • Solution Option A: via a direct customization option in PowerApps (instead of selecting a view for the subgrid, allow the user to copy/paste a fetchXML query into a text field that can contain a #RecordID# token to link back to the GUID of the record of the currently open form)

  • Solution Option B: by supporting something like the subgrid.control.setParameter("fetchxml") so that we can at least create this fetchXML dynamically and bind it to the subgrid with supported Javascript onLoad of the form or tab.  (the method explained in most of the forum  posts below). This is a reasonable amount of effort if you cannot support Option A. 

  • In a perfect world you support both Option A + B


There are hundreds of forum entries around the web using unsupported hacks to achieve the same results.


In Classic UI people used the subgrid.control.SetParameter("fetchxml") function but this is now broken in Unified Interface. In Unified Interface it appears a Retrieve Multiple Plugin is the only way to achieve this which is extremely complicated for something as simple as binding a query to a subgrid. 


Here is the only way to currently do this:


Already existing similar ideas that pretty much are all asking for the same thing:
Subgrid - Read / Write FetchXml / LayoutXml 

Subgrid - Update Fetchxml 

Adding custom fetchXML to a SubGrid - not officially supported after Dynamics CRM 2015 Update 1 

Updating the fetchxml/filter on a subgrid 

Dynamically set the sub-grid FetchXML 

Enable Custom Filters on Subgrids 

addCustomView to subgrid 

SubGrids and Related Items 



Here are links to various Blogs instructing people how to achieve this with unsupported methods but these no longer work in Unified Interface:



A google search for control.SetParameter("fetchXml"  shows almost 1000 search results which shows how important and common this request is.


Status: New
Kudo Kingpin

Here is another unsupported solution (working in Unified Interface) which is more elegant than the other ones that I have found online.

Advocate II

I kinda like this idea 🙂

Voting for option A, or at least that some sort of placeholder be respected, then we can handle everything else from FetchXML Builder.


Regular Visitor

Definitely need this!


Upvoted: this would indeed unlock many business scenarios requiring to roll records up at a parent record level. And this would also remove the need to use expansive or dirty workarounds to achieve the same.

Advocate I

@HenryJammes Glad to hear! Can you make it happen? 😉 


Also, any chance you can look at this idea here? I was surprised that the new Main Form Dialog was only available for lookups but not for subgrids and expected it to come with the subsequent release wave ... but it didn't 😞

New Member

How about using virtual entities to achieve this. It is supported and wrote up how here: Virtual entities in Dataverse – Why and how to use them? | XRM Vision


You're correct Jean-François, and this is a workaround I've used in the past - than you for detailing it in this blog article!

It's just a bit complex for low-code app makers. A supported Client API could immensely help here, so here's hoping this gets prioritized for a future wave 😉

Advocate I

@jfortin422 Thanks for sharing this alternative. I agree with @HenryJammes though, it should not require so much effort when all that is needed is to bind a custom FetchXML query to a subgrid, ideally even by defining the FetchXML query with a #token referencing the current record directly in the settings of the Subgrid. That would be a no-code solution. 

New Member

It's actually embarrassing that this is still so difficult.  I remember requesting this from Microsoft at least as back as CRM 2011.

Helper V

There are so many use cases for this, so I hope it will be prioritized soon. 


I did post an idea to create this as a PCF control 2 years ago on