Tuesday, 18 April 2023

How to validate end date to be greater than start date - Dynamics 365

 

How to validate end date to be greater than start date

 

// Validating Start and End Date

function ValidateMaintenanceEndDate(executionContext)

{

 var formContext = executionContext.getFormContext();

 var startDateField = formContext.getAttribute("new_maintenancestart");

 var endDateField = formContext.getAttribute("new_maintenanceend");

 var endDateFieldControl = formContext.getControl("new_maintenanceend");

 var startDate = startDateField.getValue();

 var endDate = endDateField.getValue();

 

 if (startDate != null && endDate != null)

 {

  startDate = new Date(startDate.toISOString().substr(0, 10));

  endDate = new Date(endDate.toISOString().substr(0, 10));

 

  endDateFieldControl.clearNotification("ErrEndDate");

 

  if (startDate >= endDate)

  {

   endDateFieldControl.setNotification("cannot be before or equal to Maintenance Start.""ErrEndDate");

  }

  else

  {

   endDateFieldControl.clearNotification("ErrEndDate");

  }

 }

}


No comments:

Post a Comment

Power Apps Drag & Drop Kanban code sample

  Introduction: The Kanban Board App Developers at a software company use the Kanban board to show their progress on development tasks and b...