It's all about the answers!

Ask a question

workItem.getValue( WorkItemAttributes.STATE ) is always null


William Kammersell (1611) | asked Oct 26 '11, 2:43 p.m.
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;
}
});
})();

14 answers



permanent link
Ralph Schoon (63.4k33646) | answered Oct 27 '11, 2:55 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
Hi William,

the script based functionality is stated as experimental.

I tried to code a calculated value provider script. My observation matches yours.
some more observations. Using this code


var state= workItem.getValue(WorkItemAttributes.STATE);


cause this in the log:


!MESSAGE Error invoking value provider 'com.ibm.team.workitem.valueproviders.VALUE_PROVIDER._o-yvQABlEeGNPIRQgLBlxQ'
!STACK 0
org.mozilla.javascript.EcmaError: ReferenceError: "WorkItemAttributes" is not defined. (GetCurentState-ScriptBasedCalculatedValueProvider.js#17)
at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3557)
at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3535)
at org.mozilla.javascript.ScriptRuntime.notFoundError(ScriptRuntime.java:3620)
at org.mozilla.javascript.ScriptRuntime.nameOrFunction(ScriptRuntime.java:1718)
at org.mozilla.javascript.ScriptRuntime.name(ScriptRuntime.java:1657)
at org.mozilla.javascript.gen.c26._c2(GetCurentState-ScriptBasedCalculatedValueProvider.js:17)
at org.mozilla.javascript.gen.c26.call(GetCurentState-ScriptBasedCalculatedValueProvider.js)
at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:401)
at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3003)
at org.mozilla.javascript.gen.c26.call(GetCurentState-ScriptBasedCalculatedValueProvider.js)
at com.ibm.team.rtc.common.scriptengine.internal.bridge.proxy.AbstractInvocationHandler$MethodHandler$1.run(AbstractInvocationHandler.java:160)
at com.ibm.team.rtc.common.scriptengine.environment.AbstractScriptEnvironment.execute(AbstractScriptEnvironment.java:74)
at com.ibm.team.rtc.common.scriptengine.internal.bridge.proxy.AbstractInvocationHandler$MethodHandler.invoke(AbstractInvocationHandler.java:156)
at com.ibm.team.rtc.common.scriptengine.internal.bridge.proxy.AbstractInvocationHandler.invokeGeneric(AbstractInvocationHandler.java:141)
at com.ibm.team.rtc.common.scriptengine.internal.bridge.proxy.AbstractInvocationHandler.invoke(AbstractInvocationHandler.java:95)
at $Proxy40.getValue(Unknown Source)
at com.ibm.team.workitem.shared.common.internal.valueProviders.ScriptAttributeValueProvider.getValue(ScriptAttributeValueProvider.java:55)
at com.ibm.team.workitem.common.internal.attributeValueProviders.AttributeValueProviderRegistry$SafeValueProvider.getValue(AttributeValueProviderRegistry.java:43)
at com.ibm.team.workitem.common.internal.model.impl.AttributeImpl.getValue(AttributeImpl.java:899)
at sun.reflect.GeneratedMethodAccessor78.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:618)
at com.ibm.team.repository.common.internal.util.ItemStore$ItemInvocationHandler.invoke(ItemStore.java:597)
at $Proxy20.getValue(Unknown Source)
at com.ibm.team.workitem.common.internal.WorkItemCommon.createWorkItem(WorkItemCommon.java:221)
at com.ibm.team.workitem.client.internal.WorkItemWorkingCopyRegistry.createNewUnconnected(WorkItemWorkingCopyRegistry.java:586)
at com.ibm.team.workitem.client.internal.WorkItemWorkingCopyRegistry.connectNew(WorkItemWorkingCopyRegistry.java:580)
at com.ibm.team.workitem.client.internal.WorkItemWorkingCopyManager.connectNew(WorkItemWorkingCopyManager.java:94)
at com.ibm.team.workitem.client.WorkItemOperation.run(WorkItemOperation.java:230)
at com.ibm.team.workitem.client.WorkItemOperation.run(WorkItemOperation.java:189)
at com.ibm.team.workitem.rcp.ui.internal.actions.NewWorkItemAction$2.runProtected(NewWorkItemAction.java:338)
at com.ibm.team.foundation.client.util.FoundationJob.run(FoundationJob.java:68)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)



This code does not throw an exception, but does also not return a value.


var state= workItem.getValue(com.ibm.team.workitem.api.common.WorkItemAttributes.STATE);
console.log("State: " + state);
return "CurrentState: " + state;


I will tryto create some work items for things I have been seeing today.

permanent link
Michael Walker (99215201157) | answered Oct 27 '11, 3:15 p.m.
William,

I retrieve the STATE value in my Value Provider script as well and have the correct value returned. Mine is run as a Calculated Value that's executed when the Owner value changes.

What type is yours and when does it get run?

permanent link
William Kammersell (1611) | answered Oct 28 '11, 1:42 p.m.
With some debugging, it looks like the issue is an issue with "internalState" being flagged as wanting the "content" rather than the "id". On line 15654 of _getIdSegment, there's the following code:


var _15=this.getAttribute(_14);
if(_15){
var _16=_15.getAttributeTypeId();
if(_2.isStringBasedType(_16)){
return "content";
}
}
return "id";


internalState is a smallString, so "content" is returned rather than "id".

This later causes a problem in line 10681 of _getAttribute with this code:


for(var i=0;i<_1e.length;i++){
_20=_20[_1e[i]];
if(_20==null){
return null;
}
}
return _20;


Since "internalState" was flagged as "content" rather than "id", this code tries to access the "content' value of "internalState" which doesn't exist. Jazz internal code that accesses the internalState correctly come into this loop with "id" rather than "content".

For others who have gotten it to work, I'd be curious if "internalState" is a smallString for you, and if so, is it still flagged as "content" and has a "content" value? This currently feels like a defect in Jazz to me. We're on Jazz 3.0.1.

permanent link
William Kammersell (1611) | answered Oct 28 '11, 1:49 p.m.
@rschoon - thanks for the help. You may be missing this line in your script if you're getting that error:

var WorkItemAttributes = com.ibm.team.workitem.api.common.WorkItemAttributes;


@miwalker - thanks for the help too. I'm using a Calculated Value script as well, and it doesn't seem to matter what it's dependent on. I made it dependent on Owner and that didn't help.

permanent link
William Kammersell (1611) | answered Oct 31 '11, 9:45 a.m.
Two other things I've tried to no avail:
* Adding a "content" 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.

permanent link
Sachin Nairy (5111320) | answered Dec 31 '11, 7:25 a.m.
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("calval");

(function() {
dojo.declare("calval", 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);
}

});
})();

permanent link
Ralph Schoon (63.4k33646) | answered Jan 04 '12, 3:09 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
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("calval");

(function() {
dojo.declare("calval", 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= (workItem.getValue("cim.example.value1"));


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

permanent link
Desh Sharma (4669) | answered Jan 12 '12, 2:46 p.m.
status always return null. Anyone knows how to fix it?

permanent link
Martin Aeschlimann (911) | answered Jan 24 '12, 4:12 a.m.
JAZZ DEVELOPER
status always return null. Anyone knows how to fix it?

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

Comments
julius sahat commented Oct 04 '13, 5:52 a.m.

 hi all


i have same issue, anyone was solved this issue? 


Ralph Schoon commented Oct 04 '13, 7:05 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

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


julius sahat commented Oct 07 '13, 12:23 a.m.

 hi Ralph,


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

THanks


julius sahat commented Oct 08 '13, 2:37 a.m.

hi All,


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


Thank u


Ralph Schoon commented Mar 20 '14, 3:39 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

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
Rob Logie (33825041) | answered Mar 18 '14, 10:56 p.m.
 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

Your answer


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