Why does RTC correctly add error indicator only first time a validator script is invoked for same field.
Below is the code for the validator script to check that user does not select a date past today. If today is 02/16/2015, and I select 02/19/2015 for date, the error indicator icon displays on the selection box, as it should. If I then select another past date, say 02/20/2015, the error indicator goes away (though in debug looks like it errored). The error indicator icon seems to toggle on and off for every selection there after, whether past or not. The server side validator catches the past date even though the error indicator icon has disappeared, so that's good. Anything I'm doing wrong or do I need to open a PMR? I'm on 5.02 server and Eclipse client.
dojo.provide("com.impediment.Invoice1DateNotPastToday");
dojo.require("com.ibm.team.workitem.api.common.Severity");
dojo.require("com.ibm.team.workitem.api.common.Status");
(function() {
var Severity = com.ibm.team.workitem.api.common.Severity;
var Status = com.ibm.team.workitem.api.common.Status;
dojo.declare("com.impediment.Invoice1DateNotPastToday", null, {
validate: function(attributeId, workItem, configuration) {
var I1Date = workItem.getValue("InvoiceDate");
var Today = new Date();
var I1Date = new Date(I1Date);
if ( (I1Date == null) || (I1Date <= Today) ) {
return Status.OK_STATUS;
}
else {
return new Status(Severity["ERROR"], "Invoice date cannot be past today.");
}
}
});
})();
dojo.require("com.ibm.team.workitem.api.common.Severity");
dojo.require("com.ibm.team.workitem.api.common.Status");
(function() {
var Severity = com.ibm.team.workitem.api.common.Severity;
var Status = com.ibm.team.workitem.api.common.Status;
dojo.declare("com.impediment.Invoice1DateNotPastToday", null, {
validate: function(attributeId, workItem, configuration) {
var I1Date = workItem.getValue("InvoiceDate");
var Today = new Date();
var I1Date = new Date(I1Date);
if ( (I1Date == null) || (I1Date <= Today) ) {
return Status.OK_STATUS;
}
else {
return new Status(Severity["ERROR"], "Invoice date cannot be past today.");
}
}
});
})();
One answer
I would assume, if you would debug your script e.g. like https://jazz.net/library/article/1360 you will find it errors and some of your assumptions are wrong.
I'd suggest to carefully read how attribute customization works, and search the internet how you can compare dates. I believe the code below works. Just using (I1Date <= Today) does not cut it, I believe. See here: http://stackoverflow.com/questions/492994/compare-dates-with-javascript
I'd suggest to carefully read how attribute customization works, and search the internet how you can compare dates. I believe the code below works. Just using (I1Date <= Today) does not cut it, I believe. See here: http://stackoverflow.com/questions/492994/compare-dates-with-javascript
/******************************************************************************* * Licensed Materials - Property of IBM * (c) Copyright IBM Corporation 2011. All Rights Reserved. * * Note to U.S. Government Users Restricted Rights: * Use, duplication or disclosure restricted by GSA ADP Schedule * Contract with IBM Corp. *******************************************************************************/ dojo.provide("org.example.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 /* * * You need to configure this script in the Process Configuration Source: ** * * */ (function() { var Severity = com.ibm.team.workitem.api.common.Severity; var Status = com.ibm.team.workitem.api.common.Status; var DateValidator = dojo.declare("org.example.DateValidator", null, { validate: function(attributeId, workItem, configuration) { // Get the configuration parameters about the severity and error message of this validator var severity= configuration.getChild("parameters").getStringDefault("severity", Severity.ERROR.name); var message= configuration.getChild("parameters").getStringDefault("message", ""); // Get the begin date attribute from the configuration and make a Date object from it var beginDateId = configuration.getChild("parameters").getStringDefault("beginDateAttributeId", ""); var beginDate = dojo.date.stamp.fromISOString(workItem.getValue(beginDateId)); // Get the current attribute's value and make a Date object from it var endDate= dojo.date.stamp.fromISOString(workItem.getValue(attributeId)); // 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); } } }); })();*