Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Dynamics 365: Unified Interface: Inject FetchXml into Subgrid

(0) ShareShare
ReportReport
Posted on by

Hello,

We have a sub-grid on the entity's form and the data of this sub-grid depends on some field's value.

To accomplish this we use

grid.control.SetParameter('fetchXml', query);

where

grid is an HTML element of the sub-grid on the entity's form

query is a string which contains a fetch xml query with our field's value.

I know that it is an unsupported way and it works for Dynamics 365 CRM with classic UI but it doesn't work in the v.9 unified interface.

I have spent some time debugging internal CRM scripts and found out that there is a Microsoft.Crm.Client.Core.Storage.DataApi.ListQuery object. And I can call it's "set_FetchXml" function to inject my own fetch xml query into this grid. And it works. But I didn't find a way how to get this object from a sub-grid HTML element.

If anyone did research how to do it, please advise.

Thanks in advance.

*This post is locked for comments

  • RHOU Profile Picture
    65 on at
    RE: Dynamics 365: Unified Interface: Inject FetchXml into Subgrid

    I just created a very detailed feature wish to make this happen here: 

    PLEASE VOTE!

    https://powerusers.microsoft.com/t5/Power-Apps-Ideas/Binding-FetchXML-to-Subgrid-with-reference-to-RecordID-to-filter/idi-p/675538

  • Suggested answer
    Daryl LaBar Profile Picture
    500 Most Valuable Professional on at
    RE: Dynamics 365: Unified Interface: Inject FetchXml into Subgrid

    I've blogged my solution to this here:   dotnetdust.blogspot.com/.../setting-sub-grid-filterxml-in-unified.html

    The code is still unsupported, but feels much more safe than anything I've seen here.

  • Community Member Profile Picture
    on at
    RE: Dynamics 365: Unified Interface: Inject FetchXml into Subgrid

    Hi, Peter! We have a very similar requirement and would like to avoid creating additional relationships and mapping the key to a linked tables.

    Were you able to find a suitable solution?

    We'd appreciate any insight you might have =)

    Thanks,

    Leo

  • Suggested answer
    MMK Profile Picture
    745 on at
    RE: Dynamics 365: Unified Interface: Inject FetchXml into Subgrid

    Hi All

    here I have solution that works for both UCI and Classic

    mkdynamicsunfied.blogspot.com/.../filter-subgrid-in-dynamics-unified-hub.html

  • Community Member Profile Picture
    on at
    RE: Dynamics 365: Unified Interface: Inject FetchXml into Subgrid

    @blackF That has been removed from Microsoft, For what you need that?

  • blackF Profile Picture
    5 on at
    RE: Dynamics 365: Unified Interface: Inject FetchXml into Subgrid

    Hi ,

    In the UCI window Microsoft.Crm.Client.Core didn't contains Storage only Framework see below.

    please help!

    thanks

    pastedimage1580623303529v1.png

  • Community Member Profile Picture
    on at
    RE: Dynamics 365: Unified Interface: Inject FetchXml into Subgrid

    Hey I have the solution of your Query. I worked on this and was able to find the solution in a supported way. The solution alos includes lined entity. Please go through my WordPress blog link. Please mark my answer if you find this helpful.

    sank8sinha.wordpress.com/.../

  • Community Member Profile Picture
    on at
    RE: Dynamics 365: Unified Interface: Inject FetchXml into Subgrid

    Hey I have the solution of your Query. I worked on this and was able to find the solution in a supported way. The solution alos includes lined entity. Please go through my WordPress blog link. Please mark my answer if you find this helpful.

    https://sank8sinha.wordpress.com/2020/01/07/adding-filtered-views-in-uci-in-dynamics-365-crm-finally-achieved/

  • Peter Bjorkmarker Profile Picture
    10 on at
    RE: Dynamics 365: Unified Interface: Inject FetchXml into Subgrid

    Thanks for the response!

    My need was to use to for link entities a few levels deep and filter on the current record. Understand that scenario does not work for you either.

    Agreed, unsupported is a pain and can get broken anytime by an update. You can of course build your own grid from scratch and use a web resource but a fair mount of work.

    Peter Björkmarker

  • JanpKentico Profile Picture
    20 on at
    RE: Dynamics 365: Unified Interface: Inject FetchXml into Subgrid

    Hi Peter,

    I am not using gridControl.getFetchXml() method - it also returns null for me, but as far as I am not using this method I don't care.

    Example of how I inject the custom fetch into my opportunity grid in the Account form.

    • Having account form with opportunity grid (show all opportunities) - grid Name 'TestOpportunity'
    • pastedimage1574413468538v1.png
    • in the account form properties, I have registered my javascript e.g. account.js with OnLoad method which is injecting the fetch into opportunity grid
    • pastedimage1574413568062v2.png
    • the account.js contains:
    • function OnLoad(executionContext) {
          var formContext = executionContext.getFormContext();
      
      	var accountId = formContext.data.entity.getId();
      	 
          var opportunitySubgrid = formContext.getControl("TestOpportunity");
      
      	var opportunityFetchXml =
              ""
                ""
                ""
                ""
                ""
                ""
                ""
                "";
      
              opportunitySubgrid._gridControl.setFilterXml(opportunityFetchXml);
              opportunitySubgrid._gridControl.refresh();
      }

    Does not matter whether the grid is somewhere in a separated account form tab.

    But I have found this injection has few limitations

    • seems it works only for "simple" fetchXml, but does not work when the fetch contains:
      • hierarchical operator='eq-or-under' - throws exception for me
      • link entity - cannot work with entity aliases
      • TOP=X record attribute is ignored

    I hope that one day we will be able to apply custom fetch in some supported way:)

    Best regards,

    Jan

    :

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Microsoft Dynamics CRM (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 83 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 52

#3
dkrishna Profile Picture

dkrishna 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans