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

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!


dojo.provide("org.example.Test");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");

(function() {
var WorkItemAttributes = com.ibm.team.workitem.api.common.WorkItemAttributes;

dojo.declare("org.example.Test", null, {

getValue: function(attribute, workItem, configuration) {
var status_value = workItem.getValue( WorkItemAttributes.STATE ); // Always null :(
var id_value = workItem.getValue( WorkItemAttributes.ID ); // This works!

return status_value;
}
});
})();

0 votes



14 answers

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

0 votes

Comments

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

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.


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

0 votes

Comments

 sorry for "var fromISOString = dojo.date.stamp.fromISOString;"..... removed

 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
"if (workItem.isAttributeSet('WorkItemAttributes.STATE')) {var currentState = workItem.getValue(WorkItemAttributes.STATE);}
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,


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

0 votes

Comments

still not working...


RTC 4.0.2

any help pls? 


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

0 votes

Comments

What does the log show? Is the state also null? Have you copied the script out of the HTML? If you make it

var workFlowState = workItem.getValue(com.ibm.team.workitem.api.common.WorkItemAttributes.STATE);

Does that work?

If we can't get further, I would suggest to open a PMR with support and let them look at your template.

1–15 items
page 2of 1 pagesof 2 pages

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

Question asked: Oct 26 '11, 2:43 p.m.

Question was seen: 13,030 times

Last updated: Mar 20 '14, 11:00 a.m.

Confirmation Cancel Confirm