One of the exciting new features, introduced in Microsoft Dynamics CRM 2015, is the rollup field type. In my colleague’s blog Microsoft Dynamics CRM 2015 new functionality: How to do aggregate and calculate rollup data, he explains how to configure a rollup field. Before configuring a rollup field, it is a good idea to review the many business scenarios and considerations outlined by Microsoft. One important consideration is the rollup calculation frequency. For each entity that contains a rollup field, a recurring system job is automatically created to asynchronously calculate the rollup. To view the system jobs:

  • Navigate to Settings > System Jobs.
  • Change the view to Recurring System Jobs.
  • Look for jobs using the Calculate rollup fields for the <entity name> entity naming convention.

If you would like to change the recurrence of an entity’s rollup calculation, click into the job and select Modify Recurrence under More Actions. The maximum recurrence setting is 1 hour.

Changing the Rollup Calculation Frequency 1

While this is useful, there may be scenarios where a rollup field needs to recalculate as the child records are being created, updated, and deleted. Luckily, the Microsoft Dynamics CRM Software Development Kit (SDK) for CRM Online and on-premises CRM 2015 provides a new message class named CalculateRollupFieldRequest. Using the SDK, you can easily create a plugin or custom workflow activity to automatically recalculate a rollup field.

Let’s consider the following business scenario:

  • You have created a custom entity named Payment. The payment entity is a child of the invoice entity.
  • On the invoice entity, you have a rollup field named Total Amount Paid. The rollup sums all payments related to the parent record.
  • Also on the invoice entity, you have a calculated field named Balance Remaining.
  • After payments are entered against an invoice, a notification is sent to the customer displaying the invoice’s balance.

The notification must reflect the latest balance

Invoice Customizations

Changing the Rollup Calculation Frequency 2

Since the notification must reflect the latest data, we cannot assume the system job has executed. Also, if the notification is automatically sent, we cannot assume the user has manually refreshed the rollup. Using the SDK, we can create a custom workflow activity to calculate the rollup value prior to sending the email notification.

Custom Workflow Activity Code

Changing the Rollup Calculation Frequency 6

The custom workflow activity requires two inputs: a reference to the invoice record and the name of the rollup field (e.g. new_totalamountpaid). Once the new CalculateInvoiceRollupField class is registered, it can be called from a workflow. For an example, please reference the screenshots below.

Send Invoice Balance Workflow

Changing the Rollup Calculation Frequency 4

Custom Workflow Activity’s Input Properties

Changing the Rollup Calculation Frequency 5

If you need help integrating this feature with your Microsoft Dynamics CRM solution or have other integrations you’d like to do with Microsoft Dynamics CRM, RSM offers a full range of services from implementation and optimization to development and support. Contact our professionals for more information on our services at 855.437.7202 or [email protected].

By: Steve Campbell – New Jersey Microsoft Dynamics CRM partner