Tuesday, 23 January 2024

Force rollup field calculation using Power Automate

 

Force rollup field calculation using Power Automate

Rollup field is a great way to capture aggregated values computed over the records related to a specified record. Rollup fields are also part of the low code approach where in it reduce writing/maintaining codes to calculate those numbers.

The rollups fields are calculated by scheduled system jobs that run asynchronously in the background. To view the rollup jobs, go to Settings > System Jobs > View > Recurring System Jobs. There are two types of recurrence jobs created one is Mass Calculate Rollup Field or Calculate Rollup Field.

The Mass Calculate Rollup Field job by default, run 12 hours after you created or updated a field. After the job completes, it is automatically scheduled to run in the distant future, approximately, in 10 years. If the field is modified, the job resets to run again in 12 hours after the update. 

The Calculate Rollup Field job processes the records that were created, updated or deleted after the last Mass Calculate Rollup Field job finished execution. The default maximum recurrence setting is one hour. There is only one Calculate Rollup Field job per entity.

The calculation of the rollup can be triggered on-demand from the user interface. Online recalculation. If you click on the calculator icon before the rollup field this will open up a Recalculate button. Pressing the button will trigger the recalculation for that record instantly.

This is all good with the lazy approach of calculation if the field is not used for real-time purposes. In the case of real-time updates, the SDK has methods to force recalculate the field. Either using plugin or custom workflow activities this can be achieved. CalculateRollupFieldRequest is the SDK method that helps achieve this.

Coming to Power Automate, we can use Web API function calculaterollupfield to achieve this force recalculation of the rollup fields. The standard Dataverse connector available for performing unbound action only, we need to use the HTTP with Azure AD connector to perform this function.

**\[UPDATE\]**: Here is the example URL of the request

https://{{orgname}}/api/data/v9.2/CalculateRollupField(Target=@Target,FieldName=@FieldName)?@Target={ "@odata.type": "Microsoft.Dynamics.CRM.systemuser", systemuserid : "00000000-0000-0000-0000-000000000000" }&@FieldName='new_fieldname'

No comments:

Post a Comment

Power Apps Drag & Drop Kanban code sample

  Introduction: The Kanban Board App Developers at a software company use the Kanban board to show their progress on development tasks and b...