Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Suggested answer

Plugin to trigger only once on create / update of multiple records in entity / table x

Posted on by 228

We have an entity which holds 3 types of Records A, B, C. Record type A is the parent of B (each A can be the parent to multiple B records) and further B is the parent of C (each B can be the parent to multiple C records). On creation / update of every record C, CalculateCommercials plugin will run that will pull all the sibling C records under a given record B and aggregate / roll-up the totals and update that parent record B with those rolled-up sum / totals. Same thing happens on update of B record totals which will roll-up the totals to grand-parent A record. The problem here is, when we create/update multiple C records under a given parent B this will trigger multiple CalculateCommercials plugin instances which is a bit inefficient & resource intensive. Is there a better approach where we let the CalculateCommercials to trigger only once irrespective of the number of C records being created / updated?

For example, if we create / update 10 C records at a given time (roughly in a 3 minute interval) we want the CalculateCommercials plugin to run only once which will roll-up the totals to B and again only once to update A, instead of 10 times (currently its triggering 10 CalculateCommercials plugin instances to roll-up to B, which in-turn trigger another 10 more instances to update grand-parent record type C).

Sometimes this chain of auto-triggers resulting in the exceeding of 2 minute time limit for the plugin instance. Is there a better approach to simplify the rolling up of totals to parent B and then on to A?

  • Suggested answer
    RodRodriguez Profile Picture
    RodRodriguez on at
    RE: Plugin to trigger only once on create / update of multiple records in entity / table x

    So, there are a couple ways to approach this, and here is one idea (I am sure there are better ways than this).  Set up a hidden "isDirty" variable/field for each of those A, B, C records.  When they change then plugin 1 sets "isDirty" is true for that record and the "higher" (B and A) records.  Then if there are no other cooldown timers running then it sets up a timer that is just under 2 minutes (the plugin timeout limit), and at the end of that timeout then it fires off the 2nd plugin that does the rollup calculations, but only for the fields that are dirty.

    That way it only does the calculations once for each field that is dirty.

    Alternatively, instead of setting up a cool down timer you could have plugin 1 do the same "isDirty" work with no timer.  And then every 2-3 minutes you set off another plugin that does just the rollups.

    Again, I am sure there are smarter/better ways to do this.

  • Raghu_b Profile Picture
    Raghu_b 228 on at
    RE: Plugin to trigger only once on create / update of multiple records in entity / table x

    Hi Rod, I've updated the question, the time interval that I'm talking about could be around 2-3 minutes.

  • RodRodriguez Profile Picture
    RodRodriguez on at
    RE: Plugin to trigger only once on create / update of multiple records in entity / table x

    Howdy!

    Just thinking out loud here, but it seems like you need to define what "at a given time" means.  10 milliseconds?  1 minute?  1 Hour?

    So, if you are going to update those 10 C records withing a 10 second time period, then what you need to do is add a 10 second "cool down" period before the calculations start.  And then only roll up the calculations once for all of the C siblings, which then fire off the calculation for B and then A.

    Additionally, you could add some type of tracking mechanism to see if any of the children or grandchildren of A have been updated within X amount of time.  If so, then start the C->B->A calculations

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans