How to use javascript to retrieve value of Contributor attirbute
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
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
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
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