Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Multi-Entity Subgrid

(1) ShareShare
ReportReport
Posted on by Microsoft Employee

Hey everyone,

I have a requirement to create a subgrid showing with 4 different entities included back in the results instead of showing 4 different subgrids.

I have a main entity which has 4 1:N relationships which I want included in the single subgrid. I have other subgrids using custom fetchxml however I am unsure about how to included results back to the grid from different relationships.

Thanks in advance

*This post is locked for comments

  • C. Dennett Profile Picture
    C. Dennett 330 on at
    RE: Multi-Entity Subgrid

    I'm not sure this is possible at all, let alone with XML. Unless the entities have identical columns there would be no way to render the results properly in a grid view. I would look more closely at Aric's answer above and see what options might work for you. I think that's probably going to be your best bet to get closest to what you want. :)

  • David Jennaway Profile Picture
    David Jennaway 14,063 on at
    RE: Multi-Entity Subgrid

    Another option might be to use virtual entities. I expect you could create a virtual entity, and create a custom data provider that would query the 4 different entities and union the results

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Multi-Entity Subgrid

    Hey Chris, unfortunately this doesn't fit my purpose. I am needing each entity to have its own row results. For example:

    Main entity result

    Sub entity result

    sub entity 2 result

    sub entity 3 result

    etc.

  • Aric Levin Profile Picture
    Aric Levin 30,188 on at
    RE: Multi-Entity Subgrid

    Hi Jason,

    Don't think this can be done properly without replicating your entities and some custom logic.

    What you could do is create an entity with the shared fields that you want of the other four entities, and basically create plugins for create/update/delete messages on the four entities to update the combined entity.

    This is probably not the way to go.

    It would be easier to create a custom web resource. The web resource will use web api to call the four related entities, and populate the rows.

    Saying that, if the four entities are sharing data, could you possibly create the four entities as a single entity.

    Hope this helps.

  • C. Dennett Profile Picture
    C. Dennett 330 on at
    RE: Multi-Entity Subgrid

    It should. The weirdness might show up in the columns though. Since not all entities will have the same columns, there will be blanks in those columns for that row. Much like when you join SQL tables, and the columns from the joined table don't exist in the base table, and you just see NULL for those columns.

    Your results should look something like:

    MainEntityColumn1    MainEntityColumn2    SubEntity1Column1    SubEntity2Column1

    <somevalue>             <somevalue>             <somevalue>              <blank>

    <somevalue>             <somevalue>             <blank>                      <somevalue>

    However, as long as your filters are solid, and your linked entities are all using the proper related columns, your records should all show up each in their own row in the subgrid. :)

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Multi-Entity Subgrid

    Thanks Chris, this looks fairly promising! Before testing this code out, will it show the records of each linked entity on a separate row?

  • Suggested answer
    gdas Profile Picture
    gdas 50,089 on at
    RE: Multi-Entity Subgrid

    Hi Jason ,

    Out of the box its not possible. You may try with custom fetch xml.

    Are you facing any issue with custom fetch xml results.

    Try to prepare the fetchxml through advance find with alias name.Hope this helps.

    stackoverflow.com/.../show-multiple-relationship-records-in-single-view

  • Suggested answer
    C. Dennett Profile Picture
    C. Dennett 330 on at
    RE: Multi-Entity Subgrid

    You should be able to do this by linking the related entities in your XML. For example, here is the XML for the "My Activities" System View:

    <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true" >
      <entity name="activitypointer" >
        <attribute name="activityid" />
        <attribute name="scheduledstart" />
        <attribute name="regardingobjectid" />
        <attribute name="prioritycode" />
        <attribute name="scheduledend" />
        <attribute name="activitytypecode" />
        <attribute name="instancetypecode" />
        <attribute name="community" />
        <order attribute="scheduledend" descending="false" />
        <filter type="and" >
          <condition attribute="statecode" operator="in" >
            <value>0</value>
            <value>3</value>
          </condition>
          <condition attribute="isregularactivity" operator="eq" value="1" />
        </filter>
        <link-entity name="activityparty" from="activityid" to="activityid" alias="aa" >
          <filter type="and" >
            <condition attribute="partyid" operator="eq-userid" />
          </filter>
        </link-entity>
      </entity>
    </fetch>


    Your XML might look something like this:

    <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true" >
      <entity name="mainEntity" >
        <attribute name="column1" />
        <attribute name="column2" />
    <...> (more attributes) <filter type="and" > <condition attribute="filterColumn" operator="in" > <value>0</value> <value>3</value> </condition> <condition attribute="anotherFilterColumn" operator="eq" value="1" /> </filter> <link-entity name="SubEntity1" from="relatedColumn" to="relatedColumn" alias="alias" > <filter type="and" > <more filter conditions, if any> </filter> </link-entity>
    <link-entity name="SubEntity2" from="relatedColumn" to="relatedColumn" alias="alias" >
          <attribute name="subEntityColumnYouWant1" />
    <attribute name="subEntityColumnYouWant2" />
        </link-entity>
    <link-entity name="SubEntity3" from="relatedColumn" to="relatedColumn" alias="alias" >
          <attribute name="subEntityColumnYouWant1" />
        </link-entity>
    <link-entity name="SubEntity4" from="relatedColumn" to="relatedColumn" alias="alias" >
          <attribute name="subEntityColumnYouWant1" />
        </link-entity>
    </entity> </fetch>

    Hopefully this helps to guide you in the right direction. Let me know if it works for you! :)
     

  • wtc.nvorhees Profile Picture
    wtc.nvorhees on at
    RE: Multi-Entity Subgrid

    That's not possible out of the box. You would be best off implementing a custom grid in HTML / JS. There are a number of libraries out there to make the development a bit easier. React.js or http://www.sparklexrm.com/ ,come to mind. There might be some third party custom grids out there that can do this as well. 

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,321 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans