Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

how to display associated account in an account subgrid view

Posted on by 2,397

Hi, I want to display associated account in an account subgrid view, is there way to achieve that and how? Thanks

*This post is locked for comments

  • Suggested answer
    Thomas David Dayman Profile Picture
    Thomas David Dayman 11,323 on at
    RE: how to display associated account in an account subgrid view

    I think this code below is what you are looking for.

    function subgridfilter()
    {
    	//get the subgrid 
    	var objSubGrid = window.parent.document.getElementById("account_subgrid");
    	//CRM loads subgrid after form is loaded.. so when we are adding script on form load.. need to wait until sub grid is loaded. 
    	// that's why we are adding a delay..
    	var isGridLoaded = null;
    	try
    	{
    		isGridLoaded = objSubGrid.control.getEntityName();
    	}
    	catch (err)
    	{
    		setTimeout(subgridfilter, 2000);
    		return;
    	}
    	if (isGridLoaded != null)
    	{
    		//when subgrid is loaded, get GUID
    		var GUIDvalue = Xrm.Page.data.entity.getId();
    		//Create FetchXML for sub grid to filter records based on GUID
    		var FetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
    			"  <entity name='account'>" +
    			"    <attribute name='accountid' />" +
    			"    <attribute name='createdon' />" +
    		    "    <order attribute='createdon' descending='true' />" +
    			"        <filter type='and'>" +
    			"          <condition attribute='accountid' operator='eq' value='" + GUIDvalue + "' />" +
    			"        </filter>" +
    			"  </entity>" +
    			"</fetch>";
    		// Layout of subgrid.
    		var LayoutXml = "<grid name='resultset' object='1' jump='accountid' select='1' preview='1' icon='1'>" +
    			" <row name='result' id='accountid'>" +
    			"<cell name='accountid' width='100' />" +
    			"<cell name='createdon' width='150' />" +
    			"</row>" +
    			"</grid>";
    		//apply layout and filtered fetchXML
    		objSubGrid.control.SetParameter("layoutXml", LayoutXml);
    		objSubGrid.control.SetParameter("fetchXml", FetchXml);
    		//Refresh grid to show filtered records only. 
    		objSubGrid.control.Refresh();
    	}
    }


    You might need to tweek the FetchXML a bit as I was quickly typing this up :)

  • sdnd2000 Profile Picture
    sdnd2000 2,397 on at
    RE: how to display associated account in an account subgrid view

    this is my idea that I can have a subgrid to display all the accounts and filter out all the accounts with current account id to get associated accounts, but we do it through it javascript? any samples?

  • Verified answer
    Thomas David Dayman Profile Picture
    Thomas David Dayman 11,323 on at
    RE: how to display associated account in an account subgrid view

    Hi sdnd,

    This thread explains it community.dynamics.com/.../145695

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,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans