Hi,
I have two fields new_dateofbirth and new_age.
data type of new_dateofbirth is "Date and Time" and data type of new_age is Whole Number.
If I give the value in new_dateofbirth field, age has to display in new_age field.
I have created a Jscript as given below and it shows the age correctly in new_age field but i want to add the script like if the age is less than 18 it has to throw an error and once we click ok in the error, value in the new_date_birth field should get clear.
function CalculateAge()
{
if(Xrm.Page.getAttribute("new_dateofbirth").getValue() != null)
{
var now = new Date();
var birthday = Xrm.Page.getAttribute("new_dateofbirth").getValue();
var monthdif = now.getMonth() - birthday.getMonth();
var nowyear = Xrm.Page.getAttribute("new_dateofbirth").getValue().getFullYear();
if(monthdif > -1)
{
Xrm.Page.getAttribute("new_age").setValue(now.getFullYear() - birthday.getFullYear());
}
else
{
Xrm.Page.getAttribute("new_age").setValue(now.getFullYear() - birthday.getFullYear()-1);
}
}
}
Thanks in advance for the answers.
Regards,
Vignesh Babu
*This post is locked for comments
I have the same question (0)