If we want to calculate the Age in a number of years using Birthdate field (i.e. Date type field) in CRM we can achieve this in multiple ways. Here we tried to achieve this functionality using MS Flow.
Below example is configured for contact entity and flow will trigger whenever the record is created in Contact Entity.
Go to Office 365 → Microsoft Flow
- Click on ‘Create from Blank’ button, to create new Flow.
- You will be redirected to below screen then click on ‘When a record is created’ option which is highlighted in below screenshot, to trigger Flow on create of Contact entity record.
- After this you will be redirected to below screen, Please select Organization Name (Your CRM Organization) and Entity name (In this case we considered Contact entity)
- After this, you need to add condition to check if Birthdate field is Empty or not to proceed.Below is fetch expression to validate the same.@empty(triggerBody()?[‘birthdate’])
- We need to add an Action to update the record and calculate Age field value in a number of* years using from expression.To update record use highlighted action as shown in below screenshot:
After this you need to select Organization Name and Entity Name once again. Here we need to select one more field i.e. Record Identifier to uniquely identify the record which needs to be updated.
Follow below screenshot to set the Record Identifier, here we select Contact:
Click on ‘Show Advanced option’ as shown in below screenshot, to populate value of Age field:
Find Age field in list then click on “Add dynamic content” then add mentioned expression as below under “Expression” tab then click OK.
Using the simple steps given above user can calculate the Age in Dynamics 365 CRM as a number of years using Microsoft Flow.
This will not calculate the correct age all the time. The age calculation will only be correct if utcNow() has passed the birth date for the given year ex) January 1, 1975 – June 18, 2019 = 44 years. If utcNow() is prior to the birth date for the given year, it will be inaccurate ex) September 1, 1975 – June 18, 2019 = 44 years per calculation, but should be 43 years.
I have updated the blog which will resolve the issue specified in the below comment.
Earlier I used to subtract Birth Year from Current Year however, in the updated blog I started calculating differences between Current Date and Birthdate and converted that result in Years.
Current Date = 20 June 2019
Birthdate = 25 June 1990
Difference in day = 10587 (i.e. 28 Years)
Let me know if you have any further queries.
But this will only show the age at point contact was created as I don;t see any dynamic update over time – so viewing the record a year later will still have same ‘age’ value as when record was created!
Yes, in this blog we have shown calculation of age when record is created. For age calculation over time, you can check if any contact’s birthday has arrived and calculate their age on their birthday using recurrence steps mentioned in below blog.