Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested answer

Show Primary Contact and Contacts(Sub-grid) records in a single Subgrid

(0) ShareShare
ReportReport
Posted on by 262

Hi All,

I have a basic requirement wherein i have used Accounts and Contacts OOTB Entities and two custom entities. Now the relationship is such that Accounts can have multiple Contacts and there can be multiple contacts against multiple accounts. Also, in Accounts we have two separate relationship of Account with Contact :   

1) Account - Primary Contact - 1 to 1 Relationship.

2) Account - Contacts(Sub-grid) - 1 to N Relationship.

My requirement is can we show the data in a view which will have Accounts - Primary Contact Record and the Contact Sub-grids record all one in a single Sub-Grid? This is a typical requirement any help will be appreciated.

  • MMK Profile Picture
    MMK 745 on at
    RE: Show Primary Contact and Contacts(Sub-grid) records in a single Subgrid

    Hi,

    a siople way  is add subgrid of contacts with all data 

    and onform load add fetchxml with whatever filter you want 

    with below code replace the xml with yours  sample code https://mkdynamicsunfied.blogspot.com/2020/04/filter-subgrid-in-dynamics-unified-hub.html

    function FilterSubgridBy(id) {

            var connectionSubgrid = window.parent.document.getElementById("GridName");


            var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
                "  <entity name='account'>" +
                "    <attribute name='accountid' />" +
                "    <attribute name='name' />" +
                "    <attribute name='createdon' />" +
                "    <attribute name='statecode' />" +
                "    <order attribute='name' descending='false' />" +
                "    <filter type='and'>" +
                "      <condition attribute='new_orderline' operator='eq' uiname='' uitype='salesorder' value='" + id + "' />" +
                "    </filter>" +
                "  </entity>" +
                "</fetch>"

            //Set the fetchxml directly to subgrid
            // filter Subgrid in Classic
            if (connectionSubgrid) {
                connectionSubgrid.control.SetParameter("fetchXml", fetchXml); //set the fetch xml to the sub grid
                connectionSubgrid.control.Refresh(); //refresh the sub grid using the new fetch xml
            } else {
                //Filter SubGrid in UCI
                var connectionSubgridControl = Xrm.Page.getControl("GridName");
                if (connectionSubgridControl) {
                    connectionSubgridControl.setFilterXml(fetchXml); //set the fetch xml to the sub grid
                    connectionSubgridControl.refresh(); //refresh the sub grid using the new fetch xml
                } else {
                    setTimeout(FilterSubgridBy(id), 1000);
                }
            }
     
    } 

  • Suggested answer
    LeoAlt Profile Picture
    LeoAlt 16,331 on at
    RE: Show Primary Contact and Contacts(Sub-grid) records in a single Subgrid

    Hi Partner,

    You could use Connect to show both primary contact and child contacts in the same subgrid with different tags.

    1.Manually action.

    For example, I have a Account Datum with primary contact Rene and child contact Susan.

    a).Create 2 connect roles in Business Management for different contact tags in subgrid.

    pastedimage1597051407713v3.png

    pastedimage1597051458887v4.png

    Here I created "Primary Contact" and "Contacts".

    b).Create a new conncet from account to contact.

    pastedimage1597051295480v1.png

    c).Choose the primary contact Rene in "Name" and "Primary Contact" in role.

    pastedimage1597051342986v2.png

    Save and close.

    Do the same thing for another contact "Susan" and choose "Contacts" for its role.

    Then open the related view "Connections".

    pastedimage1597051542483v5.png

    Here you can see primary contact and child contact are in the same subgrid with their tags.

    2.If you want to apply this function to all your account records, you could use Power Automate to create an on-demand Flow.

    a).Create a Common Data Service button Flow.

    pastedimage1597052248059v6.png

    b).Add a create records action, set the entity to "Connections".

    pastedimage1597052867969v9.png

    In "Role To", you should fill in the record Id of "Primary contact" role.

    pastedimage1597052394726v8.png

    c).Add a list records action to list all the child contacts and set their connections.

    pastedimage1597052902917v10.png

    d).Add a create record action. Here add the "Contact" role ID in "Role To" field.

    pastedimage1597052992201v11.png

    Then we can select one or multiple records and trigger this FLOW manually.

    pastedimage1597053058138v12.png

    The last thing is to create a view for connections to show this Account - Contact connections only.

    Best Regards,

    Leo

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,489 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,305 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans