Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

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

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

0 votes



One answer

Permanent link
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

1 vote

Comments

 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)

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

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 log in 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,926
× 7,486

Question asked: Jul 21 '15, 4:47 p.m.

Question was seen: 3,491 times

Last updated: Jul 23 '15, 8:24 p.m.

Confirmation Cancel Confirm