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

RTC Calculated Value triggering for any change in status or attribute

 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.

0 votes



2 answers

Permanent link
 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.

0 votes

Comments

 Lily


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


Permanent link
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.

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,953

Question asked: Jul 22 '15, 2:11 p.m.

Question was seen: 4,027 times

Last updated: Jul 23 '15, 4:34 a.m.

Confirmation Cancel Confirm