Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

Calculated Value script not behaving as expected

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.

dojo.provide("com.ibm.team.scripts.defect.test");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");

(function() {
    var WorkItemAttributes = com.ibm.team.workitem.api.common.WorkItemAttributes;
    dojo.declare("com.ibm.team.scripts.defect.test", null, {

        getValue: function(attribute, workItem, configuration) {
    var defectstate = workItem.getLabel(WorkItemAttributes.STATE);
    var reopencount = workItem.getValue("ae.corp.etisalat.workitem.attribute.test");
       var count = parseInt(reopencount);       
         if (defectstate == "New")
         {
return count+1;
  }
else
  {
  return count;
  }

        }
    });
})();

Regards,
BalaMurugan S

0 votes

Comments

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.

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



2 answers

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


0 votes

Comments

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.

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

Thanks

0 votes

Comments

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 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
× 10,953

Question asked: Jun 08 '15, 9:58 a.m.

Question was seen: 2,485 times

Last updated: Jun 08 '15, 10:12 p.m.

Confirmation Cancel Confirm