Calculated Value script not behaving as expected
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
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.
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.
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
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.
Comments
Jonas Studer
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.
console.log("defectstate")
console.log(defectstate)
if (defectstate == "New"){
console.log("Return ++");
return count+1;
} else {
console.log("Return norm");
return count;
}