Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Create Sub-Grid in Contact entity showing all records related to that Contact's Company Name (Account/Customer)

Posted on by Microsoft Employee

Hey all,

I have a custom entity for some licensing information that I have used to create a Sub-Grid in the account entity. I would like to see that same set of records when I'm on any contact record that belongs to that account. When I try to create a Sub-Grid in the contact entity, I see options for "Only Related Records" which will only show records where my Contact is assigned to this licensing entity, or "All Record Types" where I just see all Licensing entity records. Is there any way to see all records associated with a contact's Company Name (Account/Customer) even when that particular contact is not referenced in my License entity record?

Records-Options.PNG

*This post is locked for comments

  • Suggested answer
    CMilton Profile Picture
    CMilton 110 on at
    RE: Create Sub-Grid in Contact entity showing all records related to that Contact's Company Name (Account/Customer)

    A bit of a late response, but this may help out someone else in a similar position...

    What you may be able to do is create a quick view form to the related entity, which contains a sub-grid. Not many people know that you can put sub-grids in quick view forms in this situation, and it will save you the hassle of trying to take over the control via JavaScript.

    I think you will need a quick create form, which looks at the parent account. On there, you can use the same sub-grid that you are already using on the main form of the account.

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Create Sub-Grid in Contact entity showing all records related to that Contact's Company Name (Account/Customer)

    Mohd,

    I ended up trying removing window from my subgrid variable declaration (below) but it didn't seem to make a difference.  

    var subgrid = parent.document.getElementById("Licensing");

    I was able to speak with one of the developers at my agency and he helped me debug a bit (I'm pretty new/self taught so I didn't quite know how to debug efficiently), it seems you were right on where the issue is. It was not finding the Licensing subgrid. He had me try removing the parent part and when we tested that it seemed to work. I'm not sure why it needed to be that way but below is the line that ended up working.

    var subgrid = document.getElementById("Licensing");

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Create Sub-Grid in Contact entity showing all records related to that Contact's Company Name (Account/Customer)

    Your code looks fine. Just remove window from this line.

    var subgrid = parent.document.getElementById("Licensing");

    Also Put a debugger to check if all the values are coming correct in the code.

  • Rohit Suri Profile Picture
    Rohit Suri on at
    RE: Create Sub-Grid in Contact entity showing all records related to that Contact's Company Name (Account/Customer)

    CRMUser13,

    You can write a plugin on the RetreiveMultiple event of the custom entity. The plugin can check if the request has come from the sub-grid and then manipulate the query expression to suit your requirement.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Create Sub-Grid in Contact entity showing all records related to that Contact's Company Name (Account/Customer)

    Hey Mohd, thanks for the reply! I clicked on that link but unfortunately it seems to be focused on getting a custom filter applied to what options you see for a lookup. I'm needing something similar to this but for a subgrid. I found a few possible solutions out there but I'm having trouble getting them to work. Here's what I pieced together so far, it's set as an onLoad for the form and does not run into any errors. Unfortunately, it also doesn't seem to do anything... Any ideas?

    For reference:

    Current Entity: Contact

        parentcustomerid = account name field in Contact

    Subgrid Entity: Order Product Information

        pll_customer = account name field in custom "Order Product Information" entity

    Subgrid Name: Licensing

    JS:

    function Subgrid_setFilteredView(){

    var subgrid = window.parent.document.getElementById("Licensing");

    var lookupField = new Array;

    lookupField = Xrm.Page.getAttribute("parentcustomerid").getValue();

    if (lookupField != null) {

    var accountName = lookupField[0].name;

    var accountId = lookupField[0].id;

    var fetchXml;

    }

    else {

    return;

    }

    if(subgrid == null || subgrid.readyState != "complete"){

    setTimeout(Subgrid_setFilteredView, 2000);

    return;

    }

           fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +

                             "  <entity name='pll_orderproductinformation'>" +

                                                     "    <attribute name='pll_product' />" +

     "    <attribute name='modifiedon' />" +

     "   <attribute name='pll_maintenancestart' />" +

     "   <attribute name='pll_maintenancelevel' />" +

     "    <attribute name='pll_maintenanceend' />" +

     "   <attribute name='createdon' />" +

     "   <attribute name='createdby' />" +

     "   <attribute name='pll_customer' />" +

     "   <attribute name='pll_orderproductinformationid' />" +

     "   <order attribute='pll_ordername' descending='false' />" +

                             "    <filter type='and'>" +

                             "      <condition attribute='pll_customer' operator='eq' uiname='" + accountName + "' uitype='account' value='" + accountId + "' />" +

     " <condition attribute='pll_maintenanceend' operator='next-x-years' value='100' />" +

                             "    </filter>" +

                             "  </entity>" +

                             "</fetch>";

    if (subgrid.control != null) {

    subgrid.control.SetParameter("fetchXml", fetchXml);

    subgrid.control.refresh();

    }

    else {

    setTimeout(updateSubGrid, 2000);

    }

    }

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Create Sub-Grid in Contact entity showing all records related to that Contact's Company Name (Account/Customer)

    Hey Shivaram, thanks for the reply! The issue I'm running into is I need the view to filter based on the current contact's account no matter what contact record I'm currently viewing. With the out of the box functionality, the views can be set equal to specific accounts but it's not dynamic where it can always be set equal to the current customer's account. From what I've been able to find, it looks like it will have to be a javascript function to grab the subgrid control and create a custom view setting the filter equal to that records account.

    Unfortunately, I'm having a hard time piecing together what I've found online and getting it to work so far.

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Create Sub-Grid in Contact entity showing all records related to that Contact's Company Name (Account/Customer)

    You should select All Record Types in lookup setting and filter all the records you need using this link:

    www.inogic.com/.../apply-custom-filter-on-lookup-field-in-dynamic-crm-using-script

  • Suggested answer
    shivaram Profile Picture
    shivaram 3,315 on at
    RE: Create Sub-Grid in Contact entity showing all records related to that Contact's Company Name (Account/Customer)

    Hi,

    There are only the above mentioned 2 options will come for that. If you want to see other records, then you need to create a view and add filter condition based on your requiement.

    Then in subgrid, you can select your custom view.

    02742.Screenshot_5F00_2.png

    Hope it helps you

    Thanks.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans