End date should be greater than start date
Hi All,
I have created two custom attributes start date and end date. When i create WI My end date should be greater than Start date.
for eg start date - 15/02/2013 then end date - 16/02/2013
If my end date is less then 15/02/2013 then i should get error message.
How can i do this??
Regards,
Amit
2 answers
Hello Amit,
check the date validator sample here:
https://jazz.net/wiki/bin/view/Main/AttributeCustomization#Script_Based_Validation
Thanks.
Eric.
check the date validator sample here:
https://jazz.net/wiki/bin/view/Main/AttributeCustomization#Script_Based_Validation
Thanks.
Eric.
Comments
Hey Eric,
Thanks for your reply.
i went through that links and tried to resolve it , but i didn't work for me as i am new to javascript
Do you have working script for the same?
it will be very helpfull for me.
regards,
amit
Hello Amit,
sample js below (no guarantee it works - this is just a sample for which you'll have to fill the blanks, adapt..)
However, hope it will help.
Thanks.
Eric.
var DateValidator = dojo.declare("org.example.DefectDateValidate", null, {
validate: function(attributeId, workItem, configuration) {
var severity = "ERROR";
var message = "your error msg here";
var wi_type = workItem.getValue(WorkItemAttributes.TYPE);
if (wi_type != "your work item type here") {
// we may want to restrict the validation to a given type only
return Status.OK_STATUS;
}
var beginDate = dojo.date.stamp.fromISOString(workItem.getValue("your begin date"));
var endDate= dojo.date.stamp.fromISOString(workItem.getValue("your end date"));
// 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 if((beginDate == null) && (endDate == null)) {
return Status.OK_STATUS;
}else if((beginDate != null) && (endDate == null)) {
return Status.OK_STATUS;
}else {
return new Status(Severity[severity], message);
}
}
});
})();