Work item attribute calculation script getting triggered even when dependent field has not changed
In the property dialog of a custom work item attribute, I can specify dependencies on other attributes so that when those attribute values change, the associated calculation script for this attribute will be triggered by the system (at least that's what the articles claim).
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!
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
According to the document https://jazz.net/wiki/bin/view/Main/AttributeCustomization#Calculated_values :
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.
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.