Dynamics CRM- Rollup with Custom Hierarchies
CRM Custom hierarchies are very useful feature for maintaining hierarchy among records and also provide nice visualization of the Hierarchies.
With rollup fields and custom hierarchies have become even more useful to derive and visualize meaningful data in the hierarchy. In this blog, we will use how to leverage Rollup fields and Custom hierarchies to get proper data and avoid redundancy and custom calculations.
Problem statement:
Suppose you have a custom hierarchy of campaign, so a campaign can have multiple child campaigns. Each campaign has leads associated to it.
The requirement is to get the count of all the leads of the related child campaigns and also itself.
Solution:
If you want count of leads on the campaign, we can easily create a rollup field on Campaign to get the count of leads on Campaign. The rollup field will look like below:
You can see the count of leads using the above rollup below on the campaign form:
Get total lead count of child campaigns on Parent Campaign
Without hierarchy to achieve this, we would need to write a custom plugin or JavaScript to get the lead count of all the child campaigns and set it on the parent campaign.
With rollup using hierarchy, we can get this done without any calculations. See below the rollup definition for this. Note that we have now enabled “Use Hierarchy” in the rollup definition.
This will get us the count of all leads including Child campaign as well.
See the form now with the updated rollup definition, the lead count is now “8” which is the sum of lead count of all child campaigns.
Conclusion:
Leveraging Calculated fields, rollup fields and custom hierarchies we can easily build good and simple solutions, avoid custom calculations and redundant fields.