workItem.getValue( WorkItemAttributes.STATE ) is always null
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
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
Hi Ralph,
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.
Comments
sorry for "var fromISOString = dojo.date.stamp.fromISOString;"..... removed
Hi Sergio
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,"if (workItem.isAttributeSet('WorkItemAttributes.STATE')) {var currentState = workItem.getValue(WorkItemAttributes.STATE);}
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.