Start/End Date Validation (JavaScript)

on Thursday, 1 August 2013
As a CRM developer you may come across situations whereby you have to validate a start and end date pair of fields (IE the date in the end date field is the same as or later than the date in the start date field). To do so, simply implement the following 2 JavaScript functions (one on-change of the start date field, the other on-change of the end date field):

On-change of Start Date

Var startDate = Xrm.Page.getAttribute(“”); 
Var endDate = Xrm.Page.getAttribute(“”);
if (startDate.getValue() > endDate.getValue()) {
 alert(“Start Date is greater than End Date!”);
 endDate.setValue(null);
}

On-change of End Date

Var startDate = Xrm.Page.getAttribute(“”); 
Var endDate = Xrm.Page.getAttribute(“”);
if (startDate.getValue() > endDate.getValue()) {
 alert(“Start Date is greater than End Date!”);
 startDate.setValue(null);
}

Happy coding!

0 comments:

Post a Comment