It's all about the answers!

Ask a question

Calculated Value script not behaving as expected

Balamurugan Selvarasu (331330) | asked Jun 08 '15, 9:58 a.m.
Hi All,
I have a calculated value script applied for integer attribute in each transition of open the attribute value will get incremented.

But the count getting incremented twice. For Eg:. 2,4..

Find the script below.


(function() {
    var WorkItemAttributes =;
    dojo.declare("", null, {

        getValue: function(attribute, workItem, configuration) {
    var defectstate = workItem.getLabel(WorkItemAttributes.STATE);
    var reopencount = workItem.getValue("");
       var count = parseInt(reopencount);       
         if (defectstate == "New")
return count+1;
  return count;


BalaMurugan S

Jonas Studer commented Jun 08 '15, 10:25 a.m.

Hy Bala,

Try this and you will see it very fast, where it crashes.
I guess, there'll be a problem with the defectState.
Or you have a trigger behind the WorkItem which increments it automatically if you work with that value/WI.

        if (defectstate == "New"){
            console.log("Return ++");
            return count+1;
        } else {
            console.log("Return norm");
            return count;

2 answers

permanent link
Cesar Sasaki (511280121) | answered Jun 08 '15, 10:46 a.m.
Hi Balamurugan

I think it is because the scripts runs twice. It is been known that a java script to detect a change of a state (or transition) it is not possible.

Jonas Studer commented Jun 08 '15, 10:51 a.m. | edited Jun 08 '15, 10:57 a.m.

Of course it is possible.
It's not easy. But possible.

Also on my opinion, a double call can't really be the problem because he's just "GETing"  informations and won't change any value except the one he returns.

It may be, but then a "SAVE/POST"-script have to be the caller.

Cesar Sasaki commented Jun 08 '15, 11:03 a.m.

I have been able to "detect" when a state change has occurred and then increment an attribute using javascript and calculated value.. But then when you are in that "state" and just modify the workitem without any workflow change it will also increment the attribute.

permanent link
Balamurugan Selvarasu (331330) | answered Jun 08 '15, 2:14 p.m.
edited Jun 08 '15, 2:29 p.m.
Hi All,

The same calculated value script working fine with other work Items. During specific transition the field value getting incremented correctly.

Only with one work Item type I am facing this problem.


Donald Nong commented Jun 08 '15, 10:12 p.m.

Do some debugging as Jonas suggested. Note that the script will be executed multiple times on the server side during one transaction and you need to take care of this - this is different to the case where you manually edit the work item multiple times as Cesar mentioned. It should be easy to distinguish these two cases by checking the work item history.

Your answer

Register or to post your answer.