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

How to Trigger a Microsoft Flow from a Custom Button in Dynamics 365

  When using Microsoft Flow the out-of-the-box button is nested under the ‘Flow’ section and is not easy to find nor is it customizable. Tri...