It's all about the answers!

Ask a question

defect reopen count using dojo scripting calculated value


demo demo (1313) | asked Jan 26 '17, 8:53 a.m.

Hi, the following is the DOJO script to calculate the defect reopen counter, basically when ever the defect fails during testing it will be reopened, and the counter should increment by 1. Dont have a clue why the counter is incrementing twice when the defect is reopened, any idea appreciated. so this script gets executed whenever the status is changed.

dojo.provide("defectopencounter");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");
(function() {
var WorkItemAttributes = com.ibm.team.workitem.api.common.WorkItemAttributes;
dojo.declare("defectopencounter", null, {
    getValue: function(attributeId, workItem, configuration) {
    var defectcount = parseInt(workItem.getValue("defectopencounter"));
        var stat = workItem.getValue(WorkItemAttributes.STATE);
        var act=configuration.getWorkflowAction();
        if(stat === "1")
            {   
                console.log("yes status is Open");
                console.log("the current count value:" + defectcount);
                defectcount = defectcount+1;
                console.log("the current count value after addition:" + defectcount);
            }
                return parseInt(defectcount);
    }
});
})();


Comments
demo demo commented Jan 26 '17, 9:27 a.m.

also noticed its working correctly in web interface, however on eclipse client the value is incremented by 2.

Accepted answer


permanent link
Ralph Schoon (63.6k33646) | answered Jan 26 '17, 10:54 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
edited Jan 26 '17, 11:03 a.m.

Read the documentation: https://jazz.net/wiki/bin/view/Main/AttributeCustomization#Calculated_values 


As far as I can tell, the script can be called multiple times, especially if you have more dependencies. I don't know why Eclipse and Web UI are different, but I am not convinced that they have to be working the same.

Script-based calculated values

Note: You can find general information about script-based attribute customization in the Using scripts for attribute customization section.

If you configure a Script-based calculated value, the script will be executed in three cases:

  • When a work item is created, the script is executed
  • When a work item is saved, the script is executed to recalculate the value.
  • When an attribute which the current attribute depends on is changed, the value of the current attribute is recalculated. Depending on the presentations of the two attributes this may not work in all cases. 
This has been discussed at length here in the forum, you can not reliably detect a state change with a calculated value, without storing some state information in some hidden attribute. You can see what state you are in, not more. You don't see that it was a change, you don't have the state before.The access to the workflow action is only available in conditions - as mentioned in the documentation above.  

demo demo selected this answer as the correct answer

Comments
demo demo commented Jan 29 '17, 1:14 a.m.

thanks Ralph, your input guided me to the right point. All i did is removed the Status from dependency on the defectopencounter attribute. Now web and eclipse client are working as expected. thanks a lot.

Also,   var act=configuration.getWorkflowAction(); this statement is not required and can be removed.

One other answer



permanent link
Daniel Torres (7610) | answered Aug 27 '18, 7:55 p.m.

Hi, how was the final version of your script?? I'm getting the same problem, but worst cause everytime I just refresh the wepage it increments on 3 without changing state or attribute, just refreshing.

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.