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

defect reopen count using dojo scripting calculated value

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);
    }
});
})();

0 votes

Comments

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


Accepted answer

Permanent link

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

0 votes

Comments

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

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.

0 votes

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,927
× 34

Question asked: Jan 26 '17, 8:53 a.m.

Question was seen: 2,983 times

Last updated: Aug 27 '18, 7:55 p.m.

Confirmation Cancel Confirm