Introduction:
If we want to calculate the Age in no of years using OOB Birthdate field in CRM we can use multiple ways here in this blog we tried to achieve this functionality using Microsoft Flow.
To calculate Age we have used contact entity, so this flow will trigger once the record is created in MS Flow
- Click on ‘Create from Blank’ button.
- You will be redirected to below screen then click on ‘When a record is created’ option which is highlighted in below screenshot.
- After this you will be redirected to below screen, Please select Organization Name (Your CRM Organization) and Entity name (In our case we will be using Contact entity)
- After this you need to add condition to check if Birthdate field is Empty or Not.
We have used below fetch expression to validate above condition
@empty(triggerBody()?['birthdate'])
- If we find Birthdate field empty then we need to Add Action to update the record and set Age field value as ‘Birthdate field is Empty’
To update record use highlighted action as shown in the 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 identify the record which needs to be updated.
Please use below screenshot to set Record identifier.
Click on Advance Option and write Message in ‘Age’ field which you want to display if ‘Birthdate’ is empty.
- Else we need to Add Action to update the record and set Age field value (Age in No of Years) from expression
We have used below expression to calculate the Age
sub(int(formatDateTime(utcNow(),’yyyy’)),int(formatDateTime(triggerBody()?['birthdate'],’yyyy’)))
Conclusion:
Using the simple steps given above user can calculate the Age in Dynamics 365 CRM as a number of years using Microsoft Flow.