Rollup Feature is one of the interesting feature and we have already discussed about how we can make use of rollup attributes of CRM to ease our calculations in our previous blog. Retrieving rollup attribute values is not same as we do for the other attributes. Rollup attributes are used to minimize our efforts to calculate the aggregates like count, sum, etc. for any attribute like the total number of contacts an account is associated with.
On the entity form, the rollup attribute shows the value that may not be the latest value because the value of a rollup attribute is calculated based on a system job that runs on regular intervals (default interval is hourly). If we wish to see the latest value on the form then we have to recalculate the attribute using the refresh icon.
But if we need the value of a rollup attribute inside the plug-in/workflow then we have to use the CalculateRollupFieldRequest request.
If we use the traditional method to retrieve the value of a rollup attribute using the IOrganizationService.Retrieve()/ IOrganizationService.RetreiveMultiple() function then it gives us the non-updated value (the value that is present on the form).
In order to get the latest values of a rollup attribute inside a plug-in/workflow we need to follow the below steps:
- Create a rollup attribute. For example create an attribute Contact Count on account entity to hold the count of all the contacts associated with the account.
- After creating the field we created a plug-in, in this plug-in we used the CalculateRollupFieldRequest request and CalculateRollupFieldResponse response to get the latest value of the Contact Count.
- In the plug-in we also compared the value retrieved using the above request with the value retrieved using the IOraganizationService.Retreive() function.
Note: The above request is only supported for Dynamics CRM 2015 and above.
This blog discusses about a method of retrieving the rollup attribute values. These attributes can help you in lessening the efforts for calculations of the aggregates.
Thinking of Migration? We can help you. Read more here.