workItem.getValue( WorkItemAttributes.STATE ) is always null
I'm trying to write a work item customization that uses the state attribute. All of the documentation I have found, such as https://jazz.net/wiki/bin/view/Main/AttributeCustomization#Accessing_an_item_s_Status_attri says to use the value of the attribute WorkItemAttributes.STATE. However, this is always returning null. I've tried other values for getValue(), such as "status", "internalState", "state", and nothing seems to work.
Does anyone have any tips or ideas for what would be causing this not to work? I've been successful with other work item customization scripts, and other attributes, like asking for the ID, do work. Below is some simple example code. Thanks!
|
14 answers
Ralph Schoon (63.4k●3●36●46)
| answered Mar 19 '14, 3:12 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
I have used that feature since 4.0 successfully and if it did not work, it was all my fault.....
You might be missing something in the script, the required, or defining the variable. https://jazz.net/library/article/1093 Lab 5 shows some usage. Maybe you can spot an issue with your script. Comments
Rob Logie
commented Mar 19 '14, 5:42 p.m.
Hi Ralph,
Thanks for the response. Do you have a working example of usage of WorkItemAttributes.STATE that you could post ?
Thanks in advance
- Rob
Rob Logie
commented Mar 19 '14, 9:55 p.m.
I think I have solved my problem. It is when the state is being set. The value is not being set until after the work item is saved. Prior to that the vale is not set, so if you try and use it you will get a exception. You need to use workItem.isAttributeSet('WorkItemAttributes.STATE') to test if the attribute is set before you try and do anything with it. |
So what is wrong here?
dojo.provide("example.verified.State");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
dojo.require("dojo.date.stamp");
(function() {
var WorkItemAttributes = com.ibm.team.workitem.api.common.WorkItemAttributes;
var fromISOString = dojo.date.stamp.fromISOString;
dojo.declare("example.verified.State", null, {
getValue: function(attribute, workItem, configuration) {
var currentState = workItem.getValue(WorkItemAttributes.STATE);
if (currentState=="4") {
var currentDate = Date.now();
return currentDate;
}
return "";
}
});
})();
Comments
Sergio Polastri
commented Mar 19 '14, 11:22 p.m.
sorry for "var fromISOString = dojo.date.stamp.fromISOString;"..... removed
Rob Logie
commented Mar 19 '14, 11:34 p.m.
Hi Sergio
When the work item is created for the first time the var currentState = workItem.getValue(WorkItemAttributes.STATE); will throw an exception as the state does not exist. You need to use something like this
to test if the state exists. Also, I think you need to put a dependency on "status" in the attribute definition so that the code fires whenever the status is changed, |
dojo.provide("com.acme.providers.script.StateCondition");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
(function() {
var doDebug = true;
var scriptname = "StateCondition";
var WorkItemAttributes = com.ibm.team.workitem.api.common.WorkItemAttributes;
dojo.declare("com.acme.providers.script.StateCondition", null, {
matches: function(workItem, configuration) {
if (workItem.isAttributeSet('WorkItemAttributes.STATE')) {var currentState =
workItem.getValue(WorkItemAttributes.STATE);}
if(currentState=="com.ibm.team.workitem.taskWorkflow.state.s4"){
return "OK"; // Nothing to do
}
return "";
}
});
})();
Comments
Sergio Polastri
commented Mar 20 '14, 12:04 a.m.
still not working...
RTC 4.0.2
any help pls?
|
I also tried this.. but not working:
/*******************************************************************************
* Licensed Materials - Property of IBM
* (c) Copyright IBM Corporation 2011. All Rights Reserved.
*
* TotalCostScriptedCalculatedValue
*
* Note to U.S. Government Users Restricted Rights:
* Use, duplication or disclosure restricted by GSA ADP Schedule
* Contract with IBM Corp.
*******************************************************************************/
dojo.provide("com.acme.providers.script.WorkflowStateScriptedCalculatedValue");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
/**
* @see https://jazz.net/wiki/bin/view/Main/AttributeCustomization#Using_scripts_for_attribute_cust
* @see https://jazz.net/wiki/bin/view/Main/AttributeCustomization#API_Example
*/
(function() {
var doDebug = true;
var scriptname = "WorkflowStateScriptedCalculatedValue";
var WorkItemAttributes = com.ibm.team.workitem.api.common.WorkItemAttributes;
dojo.declare("com.acme.providers.script.WorkflowStateScriptedCalculatedValue", null, {
getValue: function(attribute, workItem, configuration) {
debug("Start");
var workFlowState = workItem.getValue(WorkItemAttributes.STATE);
debug("WorkflowState: " + workFlowState);
// Replace <URL> with the resource URL to the image attached to a work item
if(workFlowState=="com.ibm.team.workitem.taskWorkflow.state.s4") return "1";
return "2";
function debug(display){
if(doDebug){
console.log(scriptname + " " + display);
}
}
}
});
})();
Comments
Ralph Schoon
commented Mar 20 '14, 11:00 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
What does the log show? Is the state also null? Have you copied the script out of the HTML? If you make it
|
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.