It's all about the answers!

Ask a question

How to use javascript to retrieve value of Contributor attirbute


DH Lee (25784446) | asked Oct 31 '12, 9:42 a.m.
JAZZ DEVELOPER
edited Apr 02 '13, 4:41 a.m. by Ralph Schoon (63.5k33646)
I am customizing process template with javascript so that value of contributor attribute can be retrieved. Now I heard that "username need to be used to retrieve unique ID so that the ID can be used to retrieve value from contributor list and there is API that can be used"

Could anyone provide more information on how it can be achieved?

or is it not possible? (https://jazz.net/forum/questions/80964/how-to-get-contributor-name-by-javascript)
It would be great if someone can clarify this

2 answers



permanent link
Ralph Schoon (63.5k33646) | answered Nov 01 '12, 5:07 p.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
edited Nov 01 '12, 5:09 p.m.
 Currently you can only use .getValue() and getLabel() in scripts. That will give you the internal Id and the visible user name/id(?) for an attribute of type contributor. I am not aware of a way to query for user Ids or names in scripts except reading a contributor type attribute with a valid contributor already being set. This holds for RTC 3.x and 4.x as far as I am aware.

Comments
DH Lee commented Nov 06 '12, 10:56 p.m. | edited Nov 06 '12, 10:56 p.m.
JAZZ DEVELOPER

Hello Ralph, Thank you for answer

I am try to use

var approver = workItem.getValue("test.attribute.approver");
text = "Approve : " + approver;
console.log(text);

Where "test.attribute.approver" attribute type = contributor

However the result I get is

!ENTRY com.ibm.team.rtc.common.scriptengine 1 0 2012-11-03 16:50:36.005
!MESSAGE LOG: Approve : null <- need to obtain value from contributor attribute

Will you be able to give me an example how this can be achieved?

I am referring to http://rsjazz.wordpress.com/2012/08/02/subscribing-to-a-work-item-using-the-java-api/ which seem related, but I need more assistance.

Thank you in advance


permanent link
Ralph Schoon (63.5k33646) | answered Nov 07 '12, 2:20 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
edited Nov 07 '12, 2:24 a.m.
The post http://rsjazz.wordpress.com/2012/08/02/subscribing-to-a-work-item-using-the-java-api/ is about the Plain Java Client Libraries and not related to JavaScript. It is a pure Java RTC Client.  

I am not sure if it is possible to get at an approver using Java script.

The example below, if configured as calculated value provider for a string such as description and a dependency to the attribute (Created By) will show the contributor ID and name in the string.

/*******************************************************************************
 * Licensed Materials - Property of IBM
 * (c) Copyright IBM Corporation 2011. All Rights Reserved.
 *
 * Note to U.S. Government Users Restricted Rights: 
 * Use, duplication or disclosure restricted by GSA ADP Schedule
 * Contract with IBM Corp.
 *******************************************************************************/
dojo.provide("com.example.ContributorValueProvider");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");

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

    dojo.declare("com.example.ContributorValueProvider", null, {

        getValue: function(attribute, workItem, configuration) {
            var out = "";
            try{
                out+="Creator ID: " + workItem.getValue(WorkItemAttributes.CREATOR)+"\n";
                out+="Creator Name: " + workItem.getLabel(WorkItemAttributes.CREATOR)+"\n";   
            } catch (e) {
                out+=e.message;
            }
            console.log("Creator:" + out);
            return out;
        }
    });
})();

Comments
Ralph Schoon commented Nov 07 '12, 2:20 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

I tested this with 4.0, but I am reasonably sure it would work with 3.x as well.


DH Lee commented Nov 26 '12, 5:27 a.m.
JAZZ DEVELOPER

Hello Again Ralph, Thank you for detailed answer and example. I have studied your code and figured that I was able to retrieve ID / value of fixed (rather pre-existing) attributes. But the problem is that I am not able to retrieve ID / value of custom attribute... Is there anything I need to be aware in order to retrieve ID / value of custom attribute contributor type?

I am quite unsure where to continue my investigation...


DH Lee commented Nov 26 '12, 5:37 a.m.
JAZZ DEVELOPER

Just to add, if code required to retrieve value / ID of custom attribute (type contributor) is the same, I am suspecting configuration of the attribute might have some issue...
Will you be able to advise what may need to be checked if I am keep receiving "null"?



Ralph Schoon commented Nov 26 '12, 6:54 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

To get the value of a custom attribute use the ID from the process configuration. For example

workItem.getValue("com.ibm.my.custom.attribute.contributor");


DH Lee commented Dec 12 '12, 9:58 p.m.
JAZZ DEVELOPER

Hello Ralph, for some reason i did not receive notification for your update...

Your previous answer on "To get the value of a custom attribute use the ID from the process configuration. For example workItem.getValue("com.ibm.my.custom.attribute.contributor");"

You can see I followed same format from above post

workItem.getValue("test.attribute.approver");
still puzzled...


DH Lee commented Dec 12 '12, 10:02 p.m.
JAZZ DEVELOPER

More note, I am able to retrieve value of other custom attributes except Contributor type. Also retrieving contributor type of none customized attribute works fine...

So I am wondering if there is any restriction in doing so,
or if I will need to check my attribute setting again..


Udaya Puthuraya commented Jan 29 '13, 1:17 p.m.

Hi Lee,  I have the same issue.
Using getValue is suppose to return the UID of the value selected for custom attribute.
But it does not fetch any value for the custom attribute of contributor type.

I am able  to retrieve the value of custom attribute of contributor type  using  getLabel which returns the actual user name.  This can not be used in the java script.

I have opened a defect with jazz.net. No response yet.
https://jazz.net/jazz/web/projects/Rational%20Team%20Concert#action=com.ibm.team.workitem.viewWorkItem&id=247581

Were you able to find any solution ?


DH Lee commented Jan 29 '13, 6:30 p.m.
JAZZ DEVELOPER

Hi Udaya
I am yet to find any solutions to this issue yet. I also referred to defect 247581 and it matches the issue I am facing.

I will post again if I can find anything in regards to current issue. Thank you for sharing your thoughts

showing 5 of 8 show 3 more comments

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.