{Dynamics CRM + Customer Hierarchy} How to show all related contacts in entire customer hierarchy in Dynamics CRM 2015 onwards

Recently my friend called up for a requirement where they needed to show all contacts in customer hierarchy. Let me explain the scenario here before moving further

Suppose Account A is parent customer for Account B and Account B is the parent customer for Account C.

So the requirement is when Account A form is loaded, a sub-grid should on the form should show all the contacts of Account A + Account B + Account C. If Account B is loaded then the sub-grid should show all the contacts of Account B + Account C.

Let us approach the solution here. Ideally it is a two step solution.

Step 1 – Prepare the fetchxml which would allow us to fetch all the contacts in the entire customer hierarchy.

Step 2 – Bind the fetchxml to the sub-grid at run time to show the contacts.

Now for the first part, CRM 2015 introduces the new ‘under’ operator which eases out our task like anything. After some discussion, my friend came up with a perfect fetchxml to achieve this. For e.g the following is the fetchxml to show all the contacts in the hierarchy of ‘Account A’.



Wonderful isn’t it. It just gives you the results you want for this. With 2013 and prior versions you can imagine how much you would need to code to achieve the same.

So we have the fetchxml. Now coming to step 2 which is to bind the fetchxml dynamically to the grid.

For 2015, there is already a wonderful blog which explains this – https://joshimandarblog.wordpress.com/2015/02/04/crm-2015-applying-custom-fetchxml-to-a-subgrid-using-javascript/

As much as we learn new concepts, I think the best thing is to see them in action in real life and my genius friend hit the bulls eye on this. He is a very well know face in Dynamics CRM – Nishant Rana.

This above logic would work not only for customer – contact relationship but in other areas of hierarchy as well like finding all users in a reporting hierarchy.

Hope this helps!

About Debajit
I am a Dynamics CRM Most Valuable Professional (MVP) with 12 years of experience in Microsoft .NET Technologies and 9 years of dedicated experience in Microsoft Dynamics CRM. I have worked with companies like Microsoft, SanDisk, PwC, TMF Group and have extensive experience of implementing complex CRM solutions from both offshore and client side. Currently the face of XrmForYou.com with significant experience in delivering corporate training on Dynamics CRM and have already delivered multiple projects to client through XrmForYou.com Author of multiple tools on codeplex including the 'Role Based Views' and 'CRM-Sharepoint Metadata manager & Attachment Extractor' which are available for commercial use under XrmForYou.com For consulting/ training, drop me a note at info@xrmforyou.com or visit our website www.xrmforyou.com

One Response to {Dynamics CRM + Customer Hierarchy} How to show all related contacts in entire customer hierarchy in Dynamics CRM 2015 onwards

  1. Nishant Rana says:

    Reblogged this on Nishant Rana's Weblog and commented:
    Using Under Operation

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: