RTC Calculated Value dependent on Status is triggered by any change
I have a calculated value script that remembers the most recent time that a work item has entered the "In Progress" state - it is triggered by Status (i.e. STATE).
It is working correctly when state is changed but the script is also being triggered whenever changes are saved whilst not changing state. Any suggestions? The script follows: //Remembers when a work item enters the "In Progress" state most recently dojo.provide("client.valueProvider.currentInProgressDate"); dojo.require("dojo.date.stamp"); dojo.require("com.ibm.team.workitem.api.common.WorkItemAttributes"); (function() { var WorkItemAttributes = com.ibm.team.workitem.api.common.WorkItemAttributes; dojo.declare("client.valueProvider.currentInProgressDate", null, { getValue: function(attribute, workItem, configuration) { var now = dojo.date.stamp.toISOString(new Date(), {milliseconds:true, zulu:true}); var dayZero = dojo.date.stamp.toISOString(new Date(0), {milliseconds:true, zulu:true}); var state = workItem.getValue(WorkItemAttributes.STATE); var myOldValue = workItem.getValue(attribute); if (state) { switch (state) { case 'taskworkflow.state.s2': //In Progress return now; break; case 'taskworkflow.state.s1': //New if (myOldValue != null) { return dayZero; } break; } } return myOldValue; } }); }) (); |
Accepted answer
Yeah, it's a bit surprising (and annoying).
We got around the problem by capturing the current state in a hidden field. Whenever the script fires (always), you check the hidden field, if you are "In Progress" already, then you do not have to update the time, otherwise, you can update it, or do whatever your logic dictates.
You have to remember to update the hidden field whenever the state changes.
Ralph Schoon selected this answer as the correct answer
Comments
Lorena Almela
commented Sep 18 '14, 6:12 p.m.
Hi, I'm also working on script to try to capture date when WI status changes and I'm not able to do it as script is running on any change, not only on status updates. I'm interested in the workaround you mentioned, capturing current state in a hidden field. Could you please give me more details on it? how do you guarantee that your script to get the date will run before the one that captures the current state? Thanks and Regards,
sam detweiler
commented Sep 18 '14, 7:02 p.m.
as NZ mentions, you save the state ONLY when u care, but check it every time.
This is - unfortunately - as designed. You can detect what state you are in, but not that you changed a state. The exception is for conditions as described in https://jazz.net/wiki/bin/view/Main/AttributeCustomization.
|
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.
Comments
Looks like this is a similar question to:
https://jazz.net/forum/questions/95777/how-can-i-determine-if-a-work-item-attribute-has-changed
There is no "Add comment" button, so I'll write my question in "Answer" section:
I also need the possibility to trigger calculated value's script only when state has changed.
So I wonder if there any way to do it in the latest versions of RTC?
Currently I'm usinf 4.0.4.
extensions fire on all changes. using Javascript there is no info on the prior state.