Rolling Up Costs to a Parent Record in Microsoft Dynamics CRM

Posted By

A common CRM development request is for an automatic cost roll-up from one entity to its parent entity. For example:  totalling all Detail costs that belong to a particular Project whenever a Detail is created, updated, or deleted.

Project costs Dynamics CRM


It is possible to use javascript to calculate the totals whenever the Project is loaded or saved, but what if CRM was set up to show all Details from the main navigation area, and someone deleted one from here? The Project screen wouldn’t be open, and therefore the javascript couldn’t run. In this case, it would be better to use a plug-in because it can be triggered behind-the-scenes by a record deletion.


Project costs Dynamics CRM1

The key to this plug-in is registering 3 steps for the Detail entity: Create, Update, and Delete. Each step would have an Image, but the Create and Update steps would use a Post-Image of the entity (after the record has been changed), and the Delete step would use a Pre-Image (before the record is deleted).

Since the Image contains the fields of the record at the time it was captured, it is used to get the ID of the parent record. Child records can then be queried for this particular parent, the costs totalled, and the parent record updated.

This approach can be used to roll-up multiple levels of costs. For example, a Customer may have multiple Events, and each Event may have multiple Expenses. The plug-in that totals the Expense costs would update the Event record, which would then trigger the Update step of another plug-in to total all Event costs for the Customer.

BDO eBook - The Cloud Changes the Game

There are times in the course of your business when you have the opportunity to dramatically accelerate growth and improve day-to-day efficiencies. Recognizing