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.
Comments
Also note that a validator is not a Default value provider. You should try to be precise with what you ask.
Thanks that helped me find the answer.
I got the suggestion for this solution from:
But the link in that answer (just above the template) opens on a screen for a validator.
I should have paid more attention to the fact that this was just an example of <a> type of script based action.
Anyway, thanks again
I guess you are looking for a default value then.
Please note that there is very little information available (e.g. NOT necessary the type) on creation time. Also carefully read what is supported (and implying the limitations because what is not documented there is not supported). The workshop is more detailed.
I also tried to summarize this in https://rsjazz.wordpress.com/2016/07/15/rtc-process-customization-what-you-can-and-cannot-do/