Prayers Answered – Calculated Fields Introduced in Dynamics CRM 2015

By | October 30, 2014

Introduction:

It was one feature that other competing CRM systems had for a while and has been an “ask” of many for many years now. Calculated field means a field that has its value calculated automatically based on the formula provided.

Till date, this used to be achieved through scripting or may be a plugin or workflow. Business Rules still did not help accomplish this simple need. No deployment was ever made that did not require a simple calculation to be performed.

In CRM 2015, you can now define the formula at the time of adding the field itself. This ensures it is executed at all times, server-side. But since it is updated synchronously you can see the updates immediately upon save.

Walkthrough:

Now when you add a new attribute in CRM you will see a new option available that allows you to select the “type” of the field being created.

Add new attribute type

It currently supports the following 3 types:

Simple: Simple is the normal fields that we have had all along.

Calculated: Calculated is when you would like the value of this field to be automatically calculated based on the calculation logic provided.

Rollup: Rollup fields allow for aggregation of child record values on the Parent record. An example for this would be total Invoice amount on the Account record.

In this part of the blog, we would look at the Calculated field.

Consider an example where we need to calculate the Commission based on the type of opportunity.

If Opportunity Type is Service then commission should be 20 % of Actual Revenue and if Opportunity Type is Software then commission should be 30 % of actual Revenue.

To accomplish this,

We will first create Commission field as calculated field. As we create Commission field as Calculated Field it becomes read only on the form.

Commission field

To define the calculation for Commission field click on Edit button and that appears only when Field type is Calculated and Rollup.

Commission field type

This opens a UI similar to Business Rules where we can define calculation. For above requirement we have defined the conditions and actions as below:

Conditions and actions

When setting the action and formula, you get intellisense to support the common functions

Intellisense common functions

Intellisense for common functions

With this done, now when you create a new record, upon Save you will find the Commission automatically set.

Calculated field type is supported for the following data types – Single line text field, Option set, Two Option, Whole Number, Decimal Number, Date Time field.

Key points of Calculated Fields:

  • While specifying the conditions, you can select AND or OR operator but cannot combine the two in the same condition.
  • While designing the expressions, you can select fields from the lookup field entities i.e N:1.
  • Calculated fields cannot be updated using Business Rules.
  • Workflow does not fire on change of Calculated fields But plugins do capture the change of the Calculated fields.
  • You cannot update the value of the Calculated fields directly either manually or programmatically.

Conclusion:

Well it’s limited in the support of expressions allowed. However, it’s a good start that we can look forward to have them develop further in the versions to come.