Calculate work item 'owned by' by 'found in'
One answer
Apparently your script does not work, as there are so many problems in such a short script. I list the most obvious ones below.
1. Avoid using a class name such as "com.ibm.*". You may introduce conflicts by doing so. You can use the one suggested by the sample code, such as "com.example.ValueProvider.OwnerFound", if you don't have a better idea.
2. JavaScript is case-sensitive. You have both "workitem" and "workItem" in your script and latter will be treated as "undefined".
3. Pay attention when you copy codes from elsewhere. You have two "else return" within the "else if" block which makes no sense at all. Also the variable "severity" just appears from nowhere and should have been "category".
4. The function workItem.getValue() returns the ID of the attribute, such as "_-O6vMIPsEeSNXIoymcU8qg", not the label. If you want the readable form, use workItem.getLabel() function instead.
5. Similar to the previous point, the value provider should return an ID, such as "_o1U7dYPsEeSypNOpTJQ02A" (identifying a user), not an email address, to the "owner" attribute.
I strongly suggest you read through the attribute customization wiki page, and learn how to use Chrome and Firefox to debug JavaScript.
https://jazz.net/wiki/bin/view/Main/AttributeCustomization
https://jazz.net/library/article/1003
https://jazz.net/library/article/1360
Comments
Hi Donald,
And my current js
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
(function() {
var WorkItemAttributes= com.ibm.team.workitem.api.common.WorkItemAttributes;
dojo.declare("com.example.ValueProvider.OwnerFound", null, {
getValue: function(WorkItemAttributes) {
var catagory= workItem.getValue(WorkItemAttributes.FOUND_IN);
if ((catagory === "Product 4.9.0.2")) {
return "xxy@us.ibm.com";
}
else
{
return "no_idea@us.ibm.com";
}
}
});
})();
Do not change the signature of the call back function. Start with the sample code by using the "fill in example" link first and build you code around it, if you don't really know how the code should look like.
It appears that you completely ignored my previous advises as you got the exact same error again. If you don't understand what I talked about, I suggest you start with some basic JavaScript training first and it should actually save you much time along the way.
I will show you the script that works in my environment.
dojo.provide("com.example.ValueProvider.OwnerFound");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
(function() {
var WorkItemAttributes = com.ibm.team.workitem.api.common.WorkItemAttributes;
dojo.declare("com.example.ValueProvider.OwnerFound", null, {
getValue: function(attribute, workItem, configuration) {
var category= workItem.getValue(WorkItemAttributes.FOUND_IN);
var owner= workItem.getValue(WorkItemAttributes.OWNER);
if ((category === "Product 1.9.0.2")) {
return "bob";
} else if ((category === "Product 1.9.0.1")) {
return "dave";
} else if ((category === "Product 1.9.0.0")) {
return "deb";
} else {
return "o1U7dYPsEeSypNOpTJQ02A";
}
}
});
})();
Note that the script is for demonstration only as it _always returns at the last "else" statement and set the owner to "Bob" ("_o1U7dYPsEeSypNOpTJQ02A" is the ID for Bob in my CLM environment).