latest Post

CRM 2016 - Editable Calculated fields

They are times when there is a need to have calculated fields in CRM, prior to CRM 2015 this had to be done manually using JavaScript or with the use of business rules to a lesser extent depending on how complicated the calculations were that's why calculated fields introduced in CRM 2015 were a major plus. 

However, today I came across a calculated field that had been setup in our system by another developer, the field was simple enough it was calculating the end date of a contract when given the start date and length in months. 

The calculation has been working fine however, the problem arose when our customer wanted a modification to give them the ability to override the calculation in certain scenarios.  
To be honest I assumed this would be a simple configuration change but it wasn't quite as simple as that and I ended up having to remove the calculated field and create a new field and calculate the end date via JavaScript. 

 Prior to doing this I tried the following configurations changes which I assumed would work:

 1.) Modify calculation to only calculate if the field is null - At first I thought I could wrap the calculation in a condition to only perform the calculation if the end date field was null. However, Microsoft prevent you from selecting the current field in the list.  I.E. having a condition on the same field as the calculated field. I guess it kind of makes sense to ensure no circular references.

2.) Create boolean field "Override Date" - I then decided I would create a boolean field that the user could select from and then use this field to prevent the field from calculating in the calculation condition.  Although this worked I quickly realised that I could not then make the calculated field editable. I tried using built in configuration, business rules and custom JavaScript. However, It appears the option to edit calculated fields is disabled regardless of which method is used to do this. 

3.) Create additional date field and if set update calculated field - I then tried to use the above boolean field and if set to "allow override" an additional date field was displayed. The thought process here was the user could use this field to store the new date and then either a workflow, business rule or JavaScript would copy the field value into the calculated field. However, again it was not possible to  set a calculated field in a business rule action or workflow the field is greyed out. I then tried with JavaScript and although this worked on save the calculated field was set back to null even when setting submit mode to always in the code.

This left the only option to go back to the tried and tested method of manually performing the calculation with JavaScript..

To achieve this functionality I created a new "End Date" field and used the above boolean override field to set whether the field was editable or not. If the boolean override field was set to false the end date was calculated. I took advantage of the brilliant moment.js library to help peform the date calculations.  

The below gitgist shows the helper method  I wrote:

The below screenshot shows the UI with the field locked and date calculated as expected. 

A simple solution in the end but thought I would blog it in case it saves someone else sometime. it just goes to show things are not always as straight forward as you think they should be.  Maybe Microsoft will give us something out of the box in future releases.

Recommended Posts × +


  1. CRM of a business is good enough to calculate. They are doing great in the best regards to have a better understanding of the business. And we can meet with assignment writers uk to learn new writing techniques to complete our tasks. More power to them for the work and efforts they are making for a complete and better understanding of the business.

  2. I really want to thank Dr Emu for saving my marriage. My wife really treated me badly and left home for almost 3 month this got me sick and confused. Then I told my friend about how my wife has changed towards me. Then she told me to contact Dr Emu that he will help me bring back my wife and change her back to a good woman. I never believed in all this but I gave it a try. Dr Emu casted a spell of return of love on her, and my wife came back home for forgiveness and today we are happy again. If you are going through any relationship stress or you want back your Ex or Divorce husband you can contact his whatsapp +2347012841542 or email website: Https:// Https://