Help with Script based Validation..
I am trying to set up a validation for a predefined attribute "Priority" in "Defect" work item. I haved coded the script such that if the type=Defect and state=1 ( i.e intial state of defect), Work Item Save must force "Priority" field to be populated ( other than default 'Unassigned'). I have added "Atrribute validation" precondition for "TeamMember" role. The user is having Team Member role that performs the "Save Work Item". I have also set the Atrribute Customization - Validation rule - Pointing to the path of the script and class Name.
When the work item is saved, I see little red marker next to the field but the save works despite of the default Value "Unassigned" in it, which should fail the save and tell the user to select some other value.
Have I missed something besides the above steps. Here is my code
dojo.provide("org.example.IsDefectPrioritySetValidator");
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.WorkItemAttributes");
(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;
var PriorityValidator = dojo.declare("org.example.IsDefectPrioritySetValidator", null, {
validate: function (attributeId, workItem, configuration) {
if (workItem.getValue(WorkItemAttributes.TYPE) === "defect" && workItem.getValue(WorkItemAttributes.STATE) === "1") {
if (workItem.getValue(WorkItemAttributes.PRIORITY) === "Unassigned") {
return new Status(Severity["ERROR"], "Defect Priority Cannot Be Default");
} else {
return Status.OK_STATUS;
}
} else {
return Status.OK_STATUS;
}
}
});
})();