Date Validation on RTC attributes
Hello,
We have a requirement to implement the date validation on RTC date attributes.
There are two custom date attributes say Analysis Start Date and Analysis End Date . Never the End Analysis Date should be lesser than Start Date. And it should throw the error if the above condition is not met while save operation on WI.
We wrote a Validation script and created a validator applied on the attribute . But its not working , its throwing an error message on end date if date is less than start date , but it is able to save the Workitem.
Could you please verify the below code and let us know how to throw error and not to save WI.
dojo.provide("com.ibm.team.workitem.DateValidator");
dojo.require("com.ibm.team.workitem.api.common.Severity");
dojo.require("com.ibm.team.workitem.api.common.Status");
dojo.require("dojo.date"); // We need the date class from Dojo to compare two dates
dojo.require("dojo.date.stamp"); // We need the stamp class to work with ISO date strings
(function() {
var Severity = com.ibm.team.workitem.api.common.Severity;
var Status = com.ibm.team.workitem.api.common.Status;
var WorkItemAttributes= com.ibm.team.workitem.api.common.WorkItemAttributes;
dojo.declare("com.ibm.team.workitem.DateValidator", null, {
validate: function(attributeId, workItem, configuration) {
var severity = "ERROR";
var message = "Start Date should be less than End Date";
// Get the begin date attribute from the configuration and make a Date object from it
var beginDateId = workItem.getValue("plannedanalstart");
var beginDate = dojo.date.stamp.fromISOString(workItem.getValue(beginDateId));
// Get the current attribute's value and make a Date object from it
var endDateId = workItem.getValue("plannedanalend");
var endDate = dojo.date.stamp.fromISOString(workItem.getValue(endDateId));
// Compare the two dates and make sure endDate is not earlier than beginDate
if (dojo.date.compare(endDate, beginDate) >= 0) {
return Status.OK_STATUS;
} else {
return new Status(Severity[severity], message);
}
}
});
})();
Thank you...!
Ashwath
We have a requirement to implement the date validation on RTC date attributes.
There are two custom date attributes say Analysis Start Date and Analysis End Date . Never the End Analysis Date should be lesser than Start Date. And it should throw the error if the above condition is not met while save operation on WI.
We wrote a Validation script and created a validator applied on the attribute . But its not working , its throwing an error message on end date if date is less than start date , but it is able to save the Workitem.
Could you please verify the below code and let us know how to throw error and not to save WI.
dojo.provide("com.ibm.team.workitem.DateValidator");
dojo.require("com.ibm.team.workitem.api.common.Severity");
dojo.require("com.ibm.team.workitem.api.common.Status");
dojo.require("dojo.date"); // We need the date class from Dojo to compare two dates
dojo.require("dojo.date.stamp"); // We need the stamp class to work with ISO date strings
(function() {
var Severity = com.ibm.team.workitem.api.common.Severity;
var Status = com.ibm.team.workitem.api.common.Status;
var WorkItemAttributes= com.ibm.team.workitem.api.common.WorkItemAttributes;
dojo.declare("com.ibm.team.workitem.DateValidator", null, {
validate: function(attributeId, workItem, configuration) {
var severity = "ERROR";
var message = "Start Date should be less than End Date";
// Get the begin date attribute from the configuration and make a Date object from it
var beginDateId = workItem.getValue("plannedanalstart");
var beginDate = dojo.date.stamp.fromISOString(workItem.getValue(beginDateId));
// Get the current attribute's value and make a Date object from it
var endDateId = workItem.getValue("plannedanalend");
var endDate = dojo.date.stamp.fromISOString(workItem.getValue(endDateId));
// Compare the two dates and make sure endDate is not earlier than beginDate
if (dojo.date.compare(endDate, beginDate) >= 0) {
return Status.OK_STATUS;
} else {
return new Status(Severity[severity], message);
}
}
});
})();
Thank you...!
Ashwath