It's all about the answers!

Ask a question

RTC Calculated Value triggering for any change in status or attribute


Ankit Shah (15712) | asked Jul 22 '15, 2:11 p.m.
 I have a script which should update a counter based on changes in owner field. I put the counterstring having dependency on Owned By. Following is the script:

dojo.provide("counterString");
dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes");

(function() {
    dojo.declare("counterString", null, {

    getValue: function(attribute, workItem, configuration) {
        try { var counter = parseFloat(workItem.getValue("counterstring"));
            console.log("Count String is 1: " + counter + "\n\n");
            if (isNaN(counter)=== true)            
{
console.log("Count String now is 2: " + counter + "\n\n");
counter = 0 ;
console.log("Count String now is: 3" + counter + "\n\n");
}

else
{
console.log("Count String now is 4: " + counter + "\n\n");
            counter = counter + 1;
console.log("Count String now is 5: " + counter + "\n\n");
console.log("Exiting Counter String");
            }
            return counter.toString();
           
        }
        catch(err) {
            var txt;
            txt="There was an error on this page.\n\n";
            txt+="Error description: " + err.message + "\n\n";
            txt+="Click OK to continue.\n\n";
           
            console.log("Inside ERR Counter String" + txt + "\n\n");
        }

    }

    });
})();

This script executes every time the State or any attribute is changed. I only want script to execute when the Owned By is changed. As of now when Owned By is changed, the script executes twice, one for Owned By Change and second for the save.

2 answers



permanent link
Lily Wang (4.9k714) | answered Jul 22 '15, 9:19 p.m.
 Per document https://jazz.net/wiki/bin/view/Main/AttributeCustomization#Script_based_calculated_values
the script will be executed in 3 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. 
In you want it only counted when Owned By is changed, you need to add the condition "if owner is changed" in the script.

Comments
Ankit Shah commented Jul 23 '15, 12:26 a.m.

 Lily


Thanks for the answer. Can you shed light on how i can check if the owner is changed?


permanent link
Ralph Schoon (63.5k33646) | answered Jul 23 '15, 4:34 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
This is very hard to do. An approach you could try is:
  • Use a read only, or hidden attribute that is a calculated value and stores the user ID.
  • Your current counter script would be dependent on this attribute and only trigger when that changes.
I am not sure this would work, but I think others have used similar approaches for finding out the state changed.

Another approach would be to not use JavaScript but a Java based follow up action. In a follow up action you have the old state of the work item and the new state and you can compare them and then issue a second save to increase the counter. See https://rsjazz.wordpress.com/2012/07/31/rtc-update-parent-duration-estimation-and-effort-participant/ for an example. This extension would have to be deployed on the server and configured as operational behavior.

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.