It's all about the answers!

Ask a question

Use Calculated value Javascript to set the value of multiple attributes from a single call


Seth Bunin (11) | asked Jun 04 '20, 11:15 a.m.

 When creating a script for a calculated value, I have no problem returning the calculation to the calling attribute using the return command, but can't seem to figure out how to store a calculated value in a different attribute without calling the script in the other attribute?


I'll admit I'm not java savvy, but am just looking to explicitly set the value of a different attribute from a script in another attribute.

As an example, I have an attribute Last_State which stores the compares the current value of the Last_State and the current value of the workflow state. If they're different, I want to update the timestamp of a different attribute, and at the end of the script, update the Last_State to the workflow state using the return.

dojo.provide("Last_State_Updater");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
dojo.require("dojo.date.stamp");

(function() {
    dojo.declare("Last_State_Updater", null, {
        getValue: function(attribute, workItem, configuration) {
        var WorkItemAttributes = com.ibm.team.workitem.api.common.WorkItemAttributes;
var workFlowState = workItem.getLabel(WorkItemAttributes.STATE);
if (workFlowState != workItem.getValue("Last_State")){
switch(workFlowState){
case("Requirements development"):
//Store the current last modified timestamp in the Requirements development Time Attribute
break;
case("Design phase"):
//Store the current last modified timestamp in the Design phase Time Attribute
break;
case("Implementation phase"):
//Store the current last modified timestamp in the Implementation phase Time Attribute
break;
case("Unit test phase"):
//Store the current last modified timestamp in the Unit test phase Time Attribute
break;
default:
break;
}
}
return workFlowState.toString();
        }
    });
})();

Thanks in advance for the help!

One answer



permanent link
Ralph Schoon (63.1k33646) | answered Jun 04 '20, 2:16 p.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
edited Jun 04 '20, 2:16 p.m.
First, this is JavaScript and not Java. Not that it matters for the result.

Calculated values can only (and must) return a value. You can not 'set' anything in such a script.

As far as I know the states of a work item can not be set.


Comments
Seth Bunin commented Jun 04 '20, 4:12 p.m.

Thanks for the response and link to the slides. They were helpful. 


If I can't change more than a single value as the return in a calculated value, is there a way to define or at least know the order of the execution of the scripts? I can create the scripts separately and use getvalue to do the logic if I can define the order of execution. 


Ralph Schoon commented Jun 05 '20, 2:18 a.m. | edited Jun 05 '20, 2:38 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
The order is determined by the changes in the dependent attributes. The scripts may be called multiple times. See https://jazz.net/wiki/bin/view/Main/AttributeCustomization#Script_based_calculated_values for more details on when the scripts are called.

So you would configure a script for each attribute and that is called by the rules such as dependent attributes change. The script can get the current values of the work items attributes and can calculate the value based on these values.

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.