How do I get UID of the value from custom attribute of type contributor
I am trying to get UID of value in a custom attribute through a Java script for using in customization through Java script.
Using the link below as reference. https://jazz.net/wiki/bin/view/Main/AttributeCustomizationExamples Section : Get an item's UUID (users, iterations, project areas) I am able to get the UID of contributor type using built in attribute with the following script 1. script 1 ===================================================== dojo.provide("org.example.OwnerID"); dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes"); (function() { var WorkItemAttributes= com.ibm.team.workitem.api.common.WorkItemAttributes; dojo.declare("org.example.OwnerID", null, { getValue: function(attributeId, workItem, configuration) { return workItem.getValue(WorkItemAttributes.OWNER); } }); })(); ========================================================= Trying get the UID of custom attribute using script 2 below. script 2 ========================================================== dojo.provide("org.example.QAVerifierID"); dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes"); (function() { var WorkItemAttributes= com.ibm.team.workitem.api.common.WorkItemAttributes; dojo.declare("org.example.QAVerifierID", null, { getValue: function(attributeId, workItem, configuration) { return workItem.getValue("custom.workitem.attribute.QAVerifier"); } }); })(); =========================================================== QAVerifier is a custom attribute of type contributor. Nothing populates with the attribute linked to this script for calculated value when I change the QAVerifier value and save it. Any thoughts on what is wrong here ? or is there a other way to get UID ? |
One answer
Millard Ellingsworth (2.5k●1●24●31)
| answered Jan 30 '13, 12:23 a.m.
FORUM ADMINISTRATOR / JAZZ DEVELOPER edited Feb 11 '13, 5:09 p.m.
I have updated the work item you filed with my details from reproducing it. This seems to be a defect. Thanks for reporting it and your patience.
Researching this some more, this wiki article does not include Contributor on the list of types that can be safely read and returned from scripts.
|
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.
Comments
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 as stated earlier.
If getLabel function is used instead of getValue, it returns the actual user name.
But this can not be used in the java script to set the value of the attribute.
If the return value from getLabel is used to set the calculated value of custom attribute of type contributor, it works in front end as intended. But throws error in the server log as below.
eg: http-bio-9449-exec-265] ERROR com.ibm.team.workitem.common - Error invoking value provider 'com.ibm.team.workitem.valueproviders.VALUE_PROVIDER._JoAx0BmlEeKKwd5H9VarNA'
java.lang.IllegalArgumentException: invalid UUID [UDAYA PUTHURAYA]
at com.ibm.team.repository.common.UUID.valueOf(UUID.java:76)
Further information from more tests on the issue :
Added script 3 that gives the error as below in server log.
http-bio-9449-exec-265] ERROR com.ibm.team.workitem.common - Error invoking value provider 'com.ibm.team.workitem.valueproviders.VALUE_PROVIDER._JoAx0BmlEeKKwd5H9VarNA'
java.lang.IllegalArgumentException: invalid UUID [UDAYA PUTHURAYA]
at com.ibm.team.repository.common.UUID.valueOf(UUID.java:76)
script 3
===============================================
dojo.provide("org.example.CalculatedValue");
dojo.require("com.ibm.team.workitem.api.common.Status");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
(function() {
var Status= com.ibm.team.workitem.api.common.Status;
var WorkItemAttributes= com.ibm.team.workitem.api.common.WorkItemAttributes;
var CalculatedValue= dojo.declare("org.example.CalculatedValue", null, {
getValue: function(attributeId, workItem, configuration) {
if (workItem.getValue(WorkItemAttributes.STATE) === "3") {
return configuration.getChild("parameters").getStringDefault("unassigned_owner", "");
}
else {
return workItem.getLabel("custom.attribute.ofTypeContributor");
}
}
});
})();
===================================================================
The above script works as intended in front end. Server log has error as stated earlier.
If the else part of the above script 3 is changed as below ( for not to change the attribute value), It also works as intended in the front end.
else {
return Status.OK_STATUS;
}
Note:Status.OK_STATUS is suppose to be used only for validate functions and Not for getValue functions.
Server log has different error this time.
eg:
http-bio-9449-exec-257] ERROR com.ibm.team.workitem.common - Error invoking value provider 'com.ibm.team.workitem.valueproviders.VALUE_PROVIDER._JoAx0BmlEeKKwd5H9VarNA'
java.lang.IllegalArgumentException: invalid UUID [com.ibm.team.workitem.api.common.Status@42a942a9]
at com.ibm.team.repository.common.UUID.valueOf(UUID.java:76)