In this blogpost, we will learn to refresh a roll-up field in Power Apps / Dynamics 365 using the Web API. Before we begin, ensure you subscribe to CRM Crate to remain informed about the latest developments in the Power Platform field.
A Rollup field in Microsoft Power Apps and Dynamics 365 Customer Engagement (CE) is a type of calculated field that aggregates data from related records. Think of it like a summary that automatically updates to reflect changes in the data it summarizes. For example, you might use a Rollup field to calculate the total value of all opportunities related to a particular account or to count the number of open cases for a customer.
Here’s how it works: you define the Rollup field in the parent entity, and then specify the child entity and the aggregation you want to perform (such as sum, average, minimum, maximum, or count). Once set up, the Rollup field periodically recalculates to ensure the data is up-to-date, typically every hour by default, but you can also trigger manual recalculations if needed.
These fields are particularly useful for getting quick insights and performing analytics without needing complex queries or reports. They help keep your data organized and ensure you have the most current information at your fingertips, enhancing decision-making and efficiency in managing customer relationships and business processes.
How to automatically refresh a rollup field using Web API?
We will use the CalculateRollupField function to automatically calculate and refresh a rollup field using web API in Power Apps.
Below is the format of API URL which needs to be executed for refreshing a rollup attribute.
<OrganizationURL>/api/data/v9.2/CalculateRollupField(Target=@EntitySetName,FieldName=@FieldName)?@EntitySetName={'@odata.id':'<TableName>(<RowGUID>)'}&@FieldName= '<RollupAttributeSchemaName>'
Below are the definitions of the dynamic parameters <OrganizationURL>
, <TableName>
, <RowGUID>
, and <RollupAttributeSchemaName>
in the Web URL.
OrganizationURL
: The Organization URL of your Power App environment, for example, https://crmcratedefault.crm8.dynamics.com/.TableName
: The plural table schema name where the rollup field is placed, for example, cc_tablebs.RowGUID
: The GUID of the table row which needs to be calculated.RollupAttributeSchemaName
: The GUID of the rollup attribute.
Below is the actual API URL that will refresh our rollup field within our Power Apps environment & the response given by the API.
https://crmcratedefault.crm8.dynamics.com/api/data/v9.2/CalculateRollupField(Target=@EntitySetName,FieldName=@FieldName)?@EntitySetName={'@odata.id':'cc_tablebs(e8bc1e3c-b8b5-ee11-9078-6045bdad37bd)'}&@FieldName='cc_rollupfield'
How to refresh a rollup field in Power Automate?
We will use the CalculateRollupField and Web API format within the HTTP connector in Power Automate to refresh a rollup field, as illustrated below.
To refresh a roll-up field in Power Apps using the Web API, you can utilize a straightforward approach. By making a targeted HTTP request to the Web API endpoint associated with the specific record and field, you trigger a refresh that updates the roll-up field with the latest aggregated values. This method ensures that your data remains current and accurately reflects any changes or updates made across related records, enhancing the overall efficiency and reliability of your Power Apps solution.