Description from script based validation is not working
I can't seem to get my script based validation to work.
What I need?
When a new story is created a standard text is filled in the description field (Different text for Story & Defect, none for the rest).
What I've done:
- Script based validators are turned on
- Created new validator:
dojo.provide("com.example.common.MyClass");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
(function() {
var WorkItemAttributes = com.ibm.team.workitem.api.common.WorkItemAttributes;
dojo.declare("com.example.common.MyClass", null, {
getDefaultValue: function(attribute, workItem, configuration) {
var WorkItemType = workItem.getValue(WorkItemAttributes.TYPE);
if (WorkItemType == "defect") {
return "I am a defect";
}
return "I am no defect";
}
});
})();
- Attached the new validator to the Description attribute
What I see:
- goto web interrface: Work item - Create Work item - Defect
- Description field remains empty
I at least expected to see something happening here.
At the very least the "I am no defect" if I got the type wrong or a visible error message somewhere.
Note: If I add a Default Value to the "Desription" attribute this does work (only same text for all work item types, hence why I went script based).
Thanks in advance
Accepted answer
Did you search for any documentation before you tried that?
You selected the template for a default value provider - which obviously does not work.
See https://jazz.net/wiki/bin/view/Main/AttributeCustomization and https://jazz.net/wiki/bin/view/Main/AttributeCustomization#Validators
Create a proper validator that returns what is needed AND configure the operation behavior
No matter what presentation you choose to use, all attribute values will be validated when they are saved on the server if Attribute validation is configured as a precondition for saving [work item] in Team Configuration, Operation Behavior.
Also see https://jazz.net/library/article/1093 last two chapters.