It's all about the answers!

Ask a question

How can I determine if a work item attribute has changed

John Hetrick (261012) | asked Dec 03 '12, 6:33 p.m.
I am trying to write a javascript to set (return) the value of an attribute if the attribute it depends on has changed.  It is not important to know the value of the primary attribute, just that it changed.

I am trying to use a script based "calculated Value".  The script gets invoked when the primary attribute changes, but it also gets invoked every time the work item is saved.  This is problematic because I do not have the situation where the value of one attribute depends on the value of another attribute.  The dependency is a changed value.

The real-life goal.  There is an attribute on the work item that indicates a particular action has taken place (e.g. passed or failed system test).  I am trying to set a date stamp on another field that indicates when the primary field changed.  The value of the primary attribute (passed, failed, in progress, etc.) is not important in this context.  What is important is to know when the transition took place.

From the users perspective this information is desired on the editor next to the primary attribute.  This is not something the users want to go look up in the history.

John Hetrick

Accepted answer

permanent link
Ralph Schoon (62.9k33645) | answered Mar 25 '13, 1:38 p.m.
The only way you can detect that a specific attribute has been changed - from my experience at least - is having a calculated value provider that has only one dependency to the attribute to monitor. There are no other ways in JavaScript I would be aware of to tell you what attribute changed or what the original value was. See Lab 5 for examples.

John Hetrick selected this answer as the correct answer

Filip Matuska commented Mar 25 '13, 1:12 p.m. | edited Feb 18 '14, 2:24 a.m.

I have very similar problem. I need to know if field was changed or not.

sam detweiler commented Feb 18 '14, 5:55 a.m.

there is no reliable way in JavaScript. The prior state is not passed like in the java advisor.

One other answer

permanent link
VK L (8177153159) | answered Dec 03 '12, 11:07 p.m.
Hi John,
               The whole script will get triggered on the workitem save operation.

But, you can choose to set the timestamp value - after checking whether the particular attribute has been modified or not. If its not modified, you can set a default null value to the attribute - something like if/else.

I guess its a plugin that you are trying to configure. how is the trigger point defined?


John Hetrick commented Dec 05 '12, 6:52 a.m.

No plugin-in, just a javascript applied to a script based Calculated Value.

I have not been able to find a way to determine if a value has been changed or not.  If I could that would solve my problem. Nor have I found a way to determine if the event is a modify or a save event.  As you indicated both will run the script.

I would take any suggestions or a javascript code snippet if you have it.
John Hetrick

Your answer

Register or to post your answer.