Validator to check and throw an error message when Time Spent attribute value is greater than Estimate attribute value
Hello Team,
We need an error message to be triggered when the Time Spent Value is entered greater than the Estimate/Correction Value and the WI should not be allowed to Save.
I tried writing a script to implement this validation but it is not working as expected. It is not validating the condition when time spent is greater than estimate and throwing the error message irrespective of the value in time spent.
(Version: 7.0.2)
Could you please help and let me know if I'm missing something?
dojo.provide("com.bosch.rtc.js.client.workflow.timevalidator");
dojo.require("com.ibm.team.workitem.api.common.Severity");
dojo.require("com.ibm.team.workitem.api.common.Status");
dojo.require("com.ibm.team.workitem.api.common.timeSpent");
dojo.require("com.ibm.team.workitem.api.common.duration");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
(function() {
var doDebug = true;
Status = com.ibm.team.workitem.api.common.Status,
Severity = com.ibm.team.workitem.api.common.Severity,
timeSpent = "timeSpent",
estimate = "duration",
WorkItemAttributes = com.ibm.team.workitem.api.common.WorkItemAttributes,
dojo.declare("com.bosch.rtc.js.client.workflow.timevalidator", null, {
validate: function(attribute, workItem, configuration) {
dojo.require("com.ibm.team.workitem.api.common.Severity");
dojo.require("com.ibm.team.workitem.api.common.Status");
dojo.require("com.ibm.team.workitem.api.common.timeSpent");
dojo.require("com.ibm.team.workitem.api.common.duration");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
(function() {
var doDebug = true;
Status = com.ibm.team.workitem.api.common.Status,
Severity = com.ibm.team.workitem.api.common.Severity,
timeSpent = "timeSpent",
estimate = "duration",
WorkItemAttributes = com.ibm.team.workitem.api.common.WorkItemAttributes,
dojo.declare("com.bosch.rtc.js.client.workflow.timevalidator", null, {
validate: function(attribute, workItem, configuration) {
if((timeSpent==estimate)&&(timeSpent<=estimate)){
return Status.OK_STATUS;
} else {
return new Status( Severity["ERROR"], " Time Spent value is greater than the Estimate. Please correct the Estimate value.");
}
}
});
})();
return Status.OK_STATUS;
} else {
return new Status( Severity["ERROR"], " Time Spent value is greater than the Estimate. Please correct the Estimate value.");
}
}
});
})();
Thanks in advance.
Accepted answer
Several suggestions.
- https://jazz.net/wiki/bin/view/Main/AttributeCustomization#API_for_Javascript shows definition for a the attribute ID's including the ones you want.
- Use console.log. E.g. console.log("Estimated Invest: " + estimatedInvest);
- The log data is in \JazzTeamServer\server\liberty\servers\clm\workarea\org.eclipse.osgi\92\data\temp\default_node\SMF_WebContainer\ccm\ccm\eclipse\workspace.metadata.log if you use Liberty Profile.
- More tips in https://jazz.net/library/article/1093
- I assume you get a string back, so do not assume >= works.
- You need to configure the Attribute Validation Precondition for validation to do anything.