Work item attribute calculation script getting triggered even when dependent field has not changed
In my case, my dependency is to another calculated value, and my script is getting triggered every time I save the work item, even though the dependent attribute value has not changed.
Does this dependency association only work with user-updated attributes?
The motivation for what I'm doing is to work around the problem that RTC scripts cannot determine whether a state change has occurred. Therefore, I have created a hidden attribute to hold previous state, and I only want calculated attribute to fire when this previous state attribute changes (it also has a calculation script to update it from the new state).
Hope this make sense. Any tips would be greatly appreciated!
Accepted answer
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.
To meet your requirement, what I did is to create a hidden attribute to record the previous state. If the current state is different to the hidden previous state, the script will set a new value to the calculated attribute. Then the previous state will be updated to the same value as the current state.
Comments
Thanks, Lily, I've noticed that the calculated value script runs on the client (browser or Eclipse) when the work item is created or when a dependent attribute is changed. However, when the work item is saved, the script runs on the server (so can't use browser's debugger or console). Is there any way to get the script to run on the client when the work item is saved in order to facilitate debugging?
For the server-side script, if you are using "console.log()", you can find the debug log from "<JazzTeamServer>/server/tomcat/work/Catalina/localhost/ccm/eclipse/workspace/.metadata/.log" if you use Tomcat. If you use WAS, it's "<WebSphere>/AppServer/profiles/<profileName>/temp/<node>/<server>/ccm_war/ccm.war/eclipse/workspace/.metadata/.log".