why my calculated value script run even when the change is not triggered?
3 answers
I think the problem here is your assumption that you can detect a state change in a JavaScript attribute customization (calculated value?) for all I know you can't. The only ways to be able to do so would be the ability to access the old state which you don't have, access to the action which you don't have except in conditions or storing the old state in a hidden attribute, which I don't see.
Hi Ralph,
You just made things very confusing.
Refreshing a page does not change anything of the work item. If you see that an attribute has an incorrect value, it is a "display" issue.
The calculated value provider will be executed at different timings, and you should understand when it will be executed.
https://jazz.net/wiki/bin/view/Main/AttributeCustomization#Script_based_calculated_values
As far as I know, reusing an attribute does not share the provider configurations.
And finally, different types of work items are likely using different workflows, hence the state ID can be different. Make sure that you specify the correct state ID in your code.
Comments
Hi Donald,
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.
I'm still not sure what's going on, but here are the things you can consider.
1. When you refresh the page, the values come from the server, so you should look at the server log if you do put the console.log() for debugging purpose.
2. You cannot detect a "change" of the state using JavaScript, as you cannot retrieve the "old" value, which Ralph has already pointed out. While you can detect the "action" being used, it only works in a Condition provider, not Calculated Value provider.
3. The "Close Date" presentation appears to be read-only, is it the reason it does not get updated?