How put the creator of a workitem in a custom attribute
![](http://jazz.net/_images/myphoto/89c7800aabb61c5e988053bbea8cbe95.jpg)
We have a workitem and a custom attribute assignation and we want to put the Creator in this attribute.
The script down dosen't work.
dojo.provide("org.example.workitems.providers.AssignCalcValue");
dojo.require("com.ibm.team.workitem.api.common.connectors.HttpConnectorParameters");
dojo.require("dojo.string");
(function() {
dojo.declare("org.example.workitems.providers.AssignCalcValue", null, {
getValueSet: function(attributeId, workItem, configuration) {
console.log("1");
var WorkItemAttributes=com.ibm.team.workitem.api.common.WorkItemAttributes;
var creat= workItem.getValue(WorkItemAttributes.OWNER);
console.log("owner :" + creat);
console.log("2");
var result= [];
result.push(creat);
return result;
}
});
})();
Accepted answer
![](http://jazz.net/_images/myphoto/89c7800aabb61c5e988053bbea8cbe95.jpg)
This is a minimal calculated value that
- Reads the work item state
- Reads the work item creator name
- Reads the work item creator UUID (needed for attributes of type contributor/user)
-
Logs some data
- Returns the work item state value and the creator information as string
Configure it for the Description attribute and make it dependent on the state attribute to see what is happening.
In other contexts, you can return the creatorName to display the name or return the creatorUUID, if this is an attribute of type contributor/user/******************************************************************************* * 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.calcstate"); dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes"); (function() { var WorkItemAttributes= com.ibm.team.workitem.api.common.WorkItemAttributes; dojo.declare("com.example.calcstate", null, { getValue: function(attribute, workItem, configuration) { var creatorUUID = workItem.getValue(WorkItemAttributes.CREATOR); var creatorName = workItem.getLabel(WorkItemAttributes.CREATOR); var creatorInfo = "Creator is: " + "'" + creatorName + "'" + " UUID " + "'" + creatorUUID + "'"; console.log(creatorInfo); var state = workItem.getValue(WorkItemAttributes.STATE); var stateInfo = "Value of state is: " + "'" + state + "'"; console.log(stateInfo); return stateInfo + " " + creatorInfo; } }); })();
7 other answers
![](http://jazz.net/_images/myphoto/89c7800aabb61c5e988053bbea8cbe95.jpg)
In addition, please carefully read How should I ask a question in the Forum if I want to receive useful answers? and consider to provide more information what you want to achieve with this.
The script above is a value set and not a calculated value as the classname suggests. It would return a pick list with one user, if configured correctly. Also if configured correctly you would see some odd string (the UUID) - which is what the contributor object returns. With getLabel(), you would get the user name - as string. Dependent of what the type of the attribute is, this might or might not be working as expected, because of said limitations of the API.
![](http://jazz.net/_images/myphoto/89c7800aabb61c5e988053bbea8cbe95.jpg)
This script works
dojo.provide("org.example.workitems.providers.AssignCalcValue");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
(function() {
var WorkItemAttributes=com.ibm.team.workitem.api.common.WorkItemAttributes;
dojo.declare("org.example.workitems.providers.AssignCalcValue", null, {
getValueSet: function(attributeId, workItem, configuration) {
console.log("1");
var creat= workItem.getValue(WorkItemAttributes.OWNER);
console.log("owner :" + creat);
console.log("2");
var result= [];
result.push(creat);
return result;
}
});
})();
and returns the owner after the owner has been set and if dependencies are set.
Note, it picks the Owner not the creator, the creator is in
-
WorkItemAttributes.CREATOR
From https://jazz.net/wiki/bin/view/Main/AttributeCustomization#API_for_Javascript again see:
Only values of the following attribute types can be safely read by and returned from scripts:
- Short String
- Medium String
- Large String
- Integer
- Long
- Decimal
- Boolean
- Timestamp
- Limited support for Enumeration.
- Limited support for Items
![](http://jazz.net/_images/myphoto/89c7800aabb61c5e988053bbea8cbe95.jpg)
With a calculated value and getLabel of Creator I get the name of the Creator but I can't put it in my customize attribute.
dojo.provide("org.example.workitems.providers.AssignCalc");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
(function() {
var WorkItemAttributes= com.ibm.team.workitem.api.common.WorkItemAttributes;
dojo.declare("org.example.workitems.providers.AssignCalc", null, {
getValue: function(attribute, workItem, configuration) {
console.log("1");
var creat = workItem.getLabel(WorkItemAttributes.CREATOR);
console.log("createur :" + creat);
return creat;
}
});
})();
![](http://jazz.net/_images/myphoto/89c7800aabb61c5e988053bbea8cbe95.jpg)
I tried with your script with getValueSet and getValue of owner
the script doesn't do the trip the custom attribute is list of contributor type
![](http://jazz.net/_images/myphoto/89c7800aabb61c5e988053bbea8cbe95.jpg)
Sorry but I tried with the script down and Etat is null :
dojo.provide("org.example.workitems.providers.Validator");
dojo.require("com.ibm.team.workitem.api.common.Severity");
dojo.require("com.ibm.team.workitem.api.common.Status");
(function() {
var WorkItemAttributes= com.ibm.team.workitem.api.common.WorkItemAttributes;
dojo.declare("org.example.workitems.providers.Validator", null, {
validate: function(attribute, workItem, configuration) {
var Category= workItem.getValue(WorkItemAttributes.FILED_AGAINST);
var Status= com.ibm.team.workitem.api.common.Status;
var Etat= workItem.getValue(WorkItemAttributes.state);
console.log("HERE IS Etat VALUE" + " " + Etat);
console.log("HERE IS catégorie VALUE" + " " + Category);
![](http://jazz.net/_images/myphoto/89c7800aabb61c5e988053bbea8cbe95.jpg)
- Reads the work item state
- Returns the work item state value
Configure it for the Description attribute and make it dependent on the state attribute to see what is happening.
I have now seen the same incomplete code in many similar questions and I can not see any systematic approach of reading documentation, starting with minimal scripts and incorporating suggestions in the discussion on this and other related questions. This does not make me very optimistic that this is going anywhere.
/******************************************************************************* * 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.ValueProvider"); dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes"); (function() { var WorkItemAttributes= com.ibm.team.workitem.api.common.WorkItemAttributes; dojo.declare("com.example.ValueProvider", null, { getValue: function(attribute, workItem, configuration) { return workItem.getValue(WorkItemAttributes.STATE); } }); })();
Comments
![](http://jazz.net/_images/myphoto/e5e63d5878217b64611c1df9401b7cd3.jpg)
A slightly more ambitions version:
/*********** * 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.calcstate"); dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");(function() { var WorkItemAttributes= com.ibm.team.workitem.api.common.WorkItemAttributes; dojo.declare("com.example.calcstate", null, {
getValue: function(attribute, workItem, configuration) { var state = workItem.getValue(WorkItemAttributes.STATE); console.log("Value of state is: " + "'" + state + "'"); return "Value of state is: " + "'" + state + "'"; } });
})();
![](http://jazz.net/_images/myphoto/89c7800aabb61c5e988053bbea8cbe95.jpg)
Thank you this is ok with the sript down :
dojo.provide("org.example.workitems.providers.Validator");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
dojo.require("com.ibm.team.workitem.api.common.Status");
dojo.require("com.ibm.team.workitem.api.common.Severity");
(function() {
var WorkItemAttributes= com.ibm.team.workitem.api.common.WorkItemAttributes;
var Status = com.ibm.team.workitem.api.common.Status;
var Severity= com.ibm.team.workitem.api.common.Severity;
dojo.declare("org.example.workitems.providers.Validator", null, {
validate: function(attributeId, workItem, configuration) {
var Category= workItem.getValue(WorkItemAttributes.FILED_AGAINST);
var Etat= workItem.getValue(WorkItemAttributes.STATE);
console.log("HERE IS Etat VALUE" + " " + Etat);
console.log("HERE IS catégorie VALUE" + " " + Category);
if (Etat === "Enchainement_activites_anomalie.state.s1" && Category !== '_Ii-KkMjyEeWM1dgCThyTQQ'){
return new Status(Severity["ERROR"], "Echec Validation. Merci de renseigner Classé dans");
console.log("Nouvelle");
}
else
return Status.OK_STATUS;
}
});
})();