First of all, from the title this seems trivial isn’t it. After all as CRM consultant we do so many complex stuffs and calculating the age of a contact is just so simple!
However the point I wanted to highlight here is to use the DIFFINDAYS and host of other functions introduced in Business Rules editor and what can be more interesting than demoing it by automatic calculation of age which is so often required.
First things first. Fields like ‘Age’ of a contact or anything which increases year or year should be calculated and how many times I have seen in implementations that this field is set to numeric with free text entry. So please remember that if you have any requirement like this, please mark the field as read-only and it should be calculated based on some other field value.
So we have made the field read-only. If you are thinking wouldn’t it be nice if this field is auto calculated also, then you are on the correct way pal.
So we make the field auto calculated. We can set up this field and make it a calculated field. I have done the same. Please check for the screenshot below.
Please note here that I have kept the age field as Decimal because my requirement was to show in fraction of years. However you can keep this whole number also.
Now comes the fun part. I click on edit and the editor opens up. I set the age as show in the screen shot below. Please note that I have created another field called ‘Date of Birth’ based on which the age is calculated.
The two important functions you can notice here are DiffInDays and Now().
These functions have come up with the 2015 Online update 1 release.
Now you save and close out this field. Now when you enter the Date of Birth, the age calculates automatically.
So no more marking the field read-only and writing jscript/ plugin for calculating the age. All this is handled automatically once you set the field as calculated in CRM.
This is just one example. You can explore a host of other functions introduced and use it to your liking.
Hope this helps!