Automatically Recalculate Rollup fields using JavaScript in Dynamics 365 CE

    Roll-up fields in Dynamics 365 CE typically take around an hour to recalculate values, unless done manually. To manually trigger the recalculation, simply click on the calculator icon adjacent to the label, which will activate the “Recalculate” button.

    The automatic recalculation is contingent upon a system job running in the background of the CRM. In this article, we will explore the process of triggering a recalculation of roll-up fields using sub-grid events.

  • I have created a custom whole number field in accounts entity named No of Contacts and set the behaviour as rollup. 

  • Click on “Edit” below the behaviour field, and it will open the new window to set the rollup field. I have set the Related Entity as Contact and Aggregation as Count of Contact. Then Save and publish the field.

  • Add the field to the Accounts main form, then save and publish the form.

  • Add a web resource named autoCalculateRollup.js and add the below functions in it.

  • This web resource will add a function on the on load of contacts sub-grid. So that we can easily catch the count of contacts associated with the account and the field will calculate the count automatically using the call to the API.

  • Please refer to the Microsoft Docs on CalculateRollupField Function link here.

  • Add the function to the on load event of Accounts Main Form where the Rollup field is there.

  • The below GIF will demonstrate the automatic recalculation on the load of sub-grid.


Have a great day!
Tamilarasu Arunachalam

2 Comments

  1. Amazing Work

    ReplyDelete
  2. Thanks, I have tried this scenario its working.

    ReplyDelete
Previous Post Next Post