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

How to use javascript to retrieve value of Contributor attirbute

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

0 votes



2 answers

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

0 votes

Comments

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

0 votes

Comments

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

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

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"?


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

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

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

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 ?

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 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
× 152

Question asked: Oct 31 '12, 9:42 a.m.

Question was seen: 6,727 times

Last updated: Apr 02 '13, 4:41 a.m.

Confirmation Cancel Confirm