web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Sub-Grid in Accounts Form

(0) ShareShare
ReportReport
Posted on by

The way the Sub-Grid is setup is OK if you only want to see a list of sub accounts when in the parent record. But I want to to see a list of related accounts regardless if I'm in the parent account or not. Is this possible?

*This post is locked for comments

I have the same question (0)
  • Royal King Profile Picture
    27,686 on at
    RE: Sub-Grid in Accounts Form

    What you meant by related records?  if you want to see all the accounts related to parent record  regardless you are in parent or child account you could use addPresearch event to filter subgrid to show only related records.

    Add the following filter for the addPreSearch event handler to filter all the child records of the parent account.

    var filter ="<filter type='and'>" +

                         "<condition attribute='parentaccountid' operator='eq' value='" +Xrm.Page.getAttribute("parentaccountid").getValue()[0].id + "'/>" +
                         "</filter>";
    To find more about addPresearch event check the below posts.

    http://blogs.msdn.com/b/shraddha_dhingra/archive/2013/12/21/addpresearch-and-addcustomfilter-in-crm-2013.aspx

    http://mscrmshop.blogspot.com/2013/10/addcustomfilter-method-for-lookup.html
  • Suggested answer
    Hosk Profile Picture
    on at
    RE: Sub-Grid in Accounts Form

    You can edit subgrids to use any view you want

    On the form edit, click the subgrid and you can choose the view

  • Community Member Profile Picture
    on at
    RE: Sub-Grid in Accounts Form

    By related accounts, I mean Parent account and Sub-Accounts.

    The default seems that the list is only displayed when you're on the Parent account. What I need is to display all related accounts regardless if the selected account is the parent or not. The example would be a law firm with it's headquarters in London and offices in cities around the globe. If I select any of those offices, I want to see a list of the other offices that belong to the firm. 

  • Suggested answer
    Hosk Profile Picture
    on at
    RE: Sub-Grid in Accounts Form

    You need to create a view to show the data you want.

    What would the criteria be for the view you want, how do you know all the accounts are related.

    In this case it sounds like you want to create a view which shows all accounts with the same parent account.

    create the view and then select it in the sub grid.

  • Community Member Profile Picture
    on at
    RE: Sub-Grid in Accounts Form

    Thanks,

    that's the problem, how do you write queries to select the data?

  • Royal King Profile Picture
    27,686 on at
    RE: Sub-Grid in Accounts Form

    If you want to see all the offices  regardless whether it's headquarter or branch office ..

    you need filter account subgrid based on the parent account record. There is no supported way to filter subgrid based on lookup. 

    Here is the sample code to filter account subgrid. This script contains unsupported way of filtering subgrid.

    if (Xrm.Page.getAttribute("parentaccountid").getValue() != null &&
    Xrm.Page.getAttribute("parentaccountid").getValue()[0] != null) {
    FilterSubgrid();
    }
    function FilterSubgrid() {
    var Subgrid = document.getElementById("yoursubgridid");
    if (Subgrid == null) {
    setTimeout(function () { FilterSubgrid(); }, 2000);
    //if the grid hasn’t loaded run this again when it has
    return;
    }
    var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>"
    + "<entity name='account'>"
    + "<attribute name='name' />"
    + "<order attribute='createdon' descending='false' />"
    + "<filter type='filtertype'>"
    + "<condition attribute='parentaccountid' operator='eq' value='" + Xrm.Page.getAttribute("parentaccountid").getValue()[0].id+ "' />"
    + "</filter>"
    + "</entity>"
    + "</fetch>";
    Subgrid.control.SetParameter("fetchXml", fetchXml); //set the fetch xml to the sub grid
    Subgrid.control.Refresh(); //refresh the sub grid using the new fetch xml
    }

  • Verified answer
    Hosk Profile Picture
    on at
    RE: Sub-Grid in Accounts Form

    Create a system view for account

    www.microsoft.com/.../create-or-edit-a-public-view-for-an-entity.aspx

    www.microsoft.com/.../create-or-edit-views.aspx

    www.youtube.com/watch

    After saving and publishing you will be able to select the view on the subgrid.

    you can practise creating the view with an advanced find

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#1
UllrSki Profile Picture

UllrSki 2

#3
ED-30091530-0 Profile Picture

ED-30091530-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans