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 |
2 answers
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. Comments Of course it is possible.
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.
|
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 Comments
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
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.
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;
}