I am currently using CRM 2013 and need to calculate age. I only have DOB to go by. I need to send an email when the contact is approaching a specific age. Can this be done via workflow or business rule?
*This post is locked for comments
I am currently using CRM 2013 and need to calculate age. I only have DOB to go by. I need to send an email when the contact is approaching a specific age. Can this be done via workflow or business rule?
*This post is locked for comments
You can also achieve this without writing any custom code via Power Automate (need to use an expression for calculating age). Please refer the below link:
Using your code, when saving my changes to the entity, the age field clears and on load the form always displays "unsaved changes." Do you know what could be causing these issues?
Please find the steps-
1) Calculate the Age using Calculated field
2) Copy the Age to a whole number using Java Script (calculated field's onchange event.)
3) Write a workflow on the change of Whole number field (Having Timeout when the condition will satisfy)
The business rule where seems to be not working ang giving an error - You can't use Now(), which is of type dateTime, with the current function.
So i wrote a JavaScript to support my calculation of Age. Click Here
vjcity.blogspot.com/.../how-to-calculate-age-in-dynamic-365-crm.html
JS to calculate Age of Contact
1. Create custom field 'Age' in whole number format, and then put it in the form. Remember the schema name of this field + lock the field in form.
2. Web Resource Type: Javascript
function CalculateAge(birthday, ondate) {
// if ondate is not specified consider today's date
if (ondate == null) { ondate = new Date(); }
// if the supplied date is before the birthday returns 0
if (ondate < birthday) { return 0; }
var age = ondate.getFullYear() - birthday.getFullYear();
if (birthday.getMonth() > ondate.getMonth() || (birthday.getMonth() == ondate.getMonth() && birthday.getDate() > ondate.getDate())) { age--; }
return age;
}
function birthdateOnChange() {
// read the birthday value from the birthdate field
var birthday = Xrm.Page.getAttribute("birthdate").getValue();
// if the date contains a value calculate the age
if (birthday != null) {
// get the age
var age = CalculateAge(birthday);
// set the age to the new_age field
Xrm.Page.getAttribute("new_age").setValue(age);
}
}
Replace the 2 schema names in the code with yours.
3. Add the Web Resource to Form Libraries, then to the Event Handlers and call function "birthdateOnChange"
4. In the Form, double click the DOB field and in the event tab under Event Handlers, press add and then select library and call this function "birthdateOnChange".
5. Save and publish the entity.
6. Enter data or change data in DOB | if data already there then on form onload you will see the correct Age!
Hi Ben,
you can calculate age by using javascript, i achieved this scenario in ms crm 2016 below my code
function AgeCategory() {
var age = 0;
var Now = new Date(); //Todays Date
var Birthday = Xrm.Page.getAttribute("new_Dateofbirth").getValue();
//Get the Date of Birth value
if (Birthday != null) {
var diff = Now.getMonth() - Birthday.getMonth(); //Check to see if Birthday has already passed
if (diff > -1) //If Birthday has already occurred
{
var bd1 = Now.getFullYear() - Birthday.getFullYear();
age = bd1.toString();
}
else //If Birthday has not already occurred
{
var bd2 = Now.getFullYear() - Birthday.getFullYear() - 1;
age = bd2.toString();
}
}
}
Hi,
You need to write Custom Code to meet your requirement.
https://community.dynamics.com/crm/f/117/p/214885/570073#570073
Search the forum for the following: birthday email send
You'll find lots of responses/tips on this.