Bhubaneswar, Odisha, India
+91-8328865778
support@softchief.com

Date Add, Compare Date, Add Month in Dynamics 365 Form script

Date Add, Compare Date, Add Month in Dynamics 365 Form script

//---------------------------------------------------------------------
//REQUIREMENT : the minimum age should be more than 18 years validation.
//-----------------------------------------------------------------------
function onChangeDOB (executionContext) {
    var formContext = executionContext.getFormContext();
    var birthDate = formContext.getAttribute("birthdate").getValue(); 
    var today = new Date(); 
    var validMinDate = new Date(
        today.getFullYear()-18, 
        today.getMonth(), 
        today.getDate() , 
        today.getHours(), 
        today.getMinutes()); 
    var birthDateFieldControl = formContext.getControl("birthdate");
    if(birthDate>validMinDate){
        birthDateFieldControl.setNotification("Minimum Age must be 18 years. Choose correct Birthdate", "BDATE");
    }
    else{
        birthDateFieldControl.clearNotification("BDATE");      
    }
 };