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


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
 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
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
 Hi
I am trying to use WorkItemAttributes.STATE on RTC 4.0.2 and I am getting the same problem of nothing being returned.  Does anyone have a work around for this defect yet ?

Thanks in advance

Rob

0 votes


Permanent link
status always return null. Anyone knows how to fix it?

This looks like a bug, please file a defect against WorkItems. Thanks a lot!

0 votes

Comments

 hi all


i have same issue, anyone was solved this issue? 

This should work in 3.x and higher. See  https://jazz.net/library/article/1093 lab 5. 

 hi Ralph,


im using RTC v.3.0.1.3, is should work?
please advise

THanks

hi All,


im using RTC v.3.0.1.3, but still cannot get WorkItemAttributes.STATE?
please advise


Thank u

As already mentioned, see  https://jazz.net/library/article/1093 lab 5. The calculated value provider that presents the image in the wiki attribute also deals with the "new" state.


Permanent link
status always return null. Anyone knows how to fix it?

0 votes


Permanent link
I am trying to write a script to calculate the value of two attribute(integer) and placing in to another attribute(integer), I referred one of article in jazz wiki page, but it is not working for me. Please help me to resolve this issue.

https://jazz.net/wiki/bin/view/Main/AttributeValueProviders#Configuration

dojo.provide(&quot;calval&quot;);

(function() {
dojo.declare(&quot;calval&quot;, null, {

getValue: function(attributeId, workItem, configuration) {
var prva1= (workItem.getValue(String int1));
var prva2= (workItem.getValue(String int2));
var prva3= (workItem.getValue(String int3));
prva3 = (prva1*prva2);
return (prva3);
}

});
})();


Hi,

you need to provide the ID of the attribute in the getValue statement e.g.


var prva1= &#40;workItem.getValue&#40;&quot;cim.example.value1&quot;&#41;&#41;;


I have been able to successfully access work item attributes in general that way.

0 votes


Permanent link
I am trying to write a script to calculate the value of two attribute(integer) and placing in to another attribute(integer), I referred one of article in jazz wiki page, but it is not working for me. Please help me to resolve this issue.

https://jazz.net/wiki/bin/view/Main/AttributeValueProviders#Configuration

dojo.provide(&quot;calval&quot;);

(function() {
dojo.declare(&quot;calval&quot;, null, {

getValue: function(attributeId, workItem, configuration) {
var prva1= (workItem.getValue(String int1));
var prva2= (workItem.getValue(String int2));
var prva3= (workItem.getValue(String int3));
prva3 = (prva1*prva2);
return (prva3);
}

});
})();

0 votes


Permanent link
Two other things I've tried to no avail:
* Adding a &quot;content&quot; attribute to each state. RTC doesn't like this and gives a compilation error that states cannot have content.
* Querying for 'com.ibm.team.workitem.attribute.state' and changing its datatype to 'integer' rather than 'smallString'. RTC doesn't like this as that 'com.ibm.team.workitem.attribute.state' attribute isn't set for the work item (although it's in the process configuration).

Also, perhaps this is a migration issue, as we migrated from RTC 2 to 3.0.1.

0 votes

1–15 items
page 1of 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: 19,142 times

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

Confirmation Cancel Confirm