Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

CRM 2013 - Update values throughout the hierarchy.

Posted on by Microsoft Employee

Hi,

We're looking for the best approach to updating values throughout the hierarchy of Accounts for our CRM 2013 solution.

The Account entity form has two custom numerical fields: 'Number of employees' and 'Group number of employees'.

Also, an Account entity record can have 'Parent' Account as well as a 'Grand Parent' Account.

2543.accounts.png

'Group number of employees' is a sum of all 'Number of employees' values across all Accounts. We need to make sure that whenever the value of 'Number of employees' changes on any of the Accounts the 'Group number of employees' will be updated and the value redistributed across the hierarchy.

i.e.:

- If 'Number of employees' is updated on AC 1 from 0 to 50, the 'Group number of employees' number should be updated to 550 on all accounts - AC1, AC2, AC3, AC4, and AC5.

- If 'Number of employees' is updated on AC 2 from 250 to 350, the 'Group number of employees' number should be updated to 600 on all accounts - AC1, AC2, AC3, AC4, and AC5.

- If 'Number of employees' is updated on AC 4 from 100 to 500, the 'Group number of employees' number should be updated to 900 on all accounts - AC1, AC2, AC3, AC4, and AC5.

 

We've been trying to use the Generic Rollup solution (https://crmgenericrollup.codeplex.com/) however, this will work only when updating Parent records but not Child.

Any help and suggestions are appreciated.

Many thanks.

*This post is locked for comments

  • Verified answer
    Aiden Kaskela Profile Picture
    Aiden Kaskela 19,692 on at
    RE: CRM 2013 - Update values throughout the hierarchy.

    Hi,

    Since you're working in 2013, your options are more limited than in 2015 (which has an Under condition). I think you'll need to handle this recursively in a plugin. Register a plugin on the account that fires when No. of Employee changes. Here's the plugin logic:

    1. When that field is updated, get the root account in your hierarchy. From your account, keep getting the parent account until there isn't one. In your example, you'd end up with AC1
    2. Keep a list of all accounts that need to be updated and add AC1
    3. Query for all accounts with a parent account IN (account's at that level - AC1). This should return AC2 and AC3.
    4. Add this list of accounts to the list in step 2
    5. Repeat step 3 with the accounts at the new level (2 & 3, returns 4 & 5). Continue until you get no more results, so you're at the bottom of the hierarchy.
    6. With the full list of accounts (from step 2), calculate the new group total and set that field on each account.
    7. Use a ExecuteMultipleRequest to update all of those accounts in a single SDK call.

    That should do it. If you had 2015, you could simplify steps 3, 4, and 5 by querying for accounts UNDER the root, but the rest of it would be the same. If you don't have any development resources, I could build this out for you pretty quickly.

    Hope this helps! I'd appreciate if you'd mark this as Answering your question.

    Thanks,

      Aiden

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