It's all about the answers!

Ask a question

Calculate work item 'owned by' by 'found in'


jeff mccallum (302912) | asked Jul 21 '15, 4:47 p.m.
 Hi,
I am attempting to set the 'Owned by' field based on the category selected.

Here is my javascript

dojo.provide("com.ibm.team.workitem.attribute.owner");

dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");


(function() {
var WorkItemAttributes= com.ibm.team.workitem.api.common.WorkItemAttributes;

dojo.declare("com.ibm.team.workitem.attribute.owner", null, {

    getValue: function(workitem) {


        var catagory= workItem.getValue(WorkItemAttributes.FOUND_IN);
        if ((catagory === "Product 1.9.0.2")) {
return "xxy@us.ibm.com";
        } else if ((catagory === "Product 1.9.0.1")) { 
            else return "xxyy@us.ibm.com";
        } else if ((severity === "Product 1.9.0.0")) { 
else return "xxyyy@us.ibm.com";
        } else {
        return "no_idea@us.ibm.com";
        }
    }
});
})();

One answer



permanent link
Donald Nong (14.5k614) | answered Jul 22 '15, 1:09 a.m.
edited Jul 22 '15, 1:18 a.m.
Next time you should make your post as a question, otherwise no one knows the purpose that you are sharing your script to others.
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
jeff mccallum commented Jul 23 '15, 5:28 p.m.

 Hi Donald,

Thank you for the help.

Output from my debug
Problems executing value provider for {0}: workitem is not defined. ReferenceError: workitem is not defined
    at dojo.declare.getValue (test.js:15:23)
    at dojo.declare.getValue (https://cmccm.usca.ibm.com:9443/ccm/web/_js/?exclude=B&include=com.ibm.team…rnal.page.WorkItemPageView&ss=Gw93y&_proxyURL=%2Fccm&locale=en-us:29634:56)
    at dojo.declare._handleValueWhenDependencyChanged (https://cmccm.usca.ibm.com:9443/ccm/web/_js/?exclude=B&include=com.ibm.team…rnal.page.WorkItemPageView&ss=Gw93y&_proxyURL=%2Fccm&locale=en-us:29807:19)
    at null.<anonymous> (https://cmccm.usca.ibm.com:9443/ccm/web/_js/?exclude=B&include=com.ibm.team…ernal.page.WorkItemPageView&ss=Gw93y&_proxyURL=%2Fccm&locale=en-us:29847:6)


jeff mccallum commented Jul 23 '15, 5:30 p.m.

 And my current js

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(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";
        }
    }
});
})();


Donald Nong commented Jul 23 '15, 8:23 p.m. | edited Jul 23 '15, 8:24 p.m.

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).

Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.