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;
}
});
}) ();
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.
Comments
Brian Fleming
Dec 04 '12, 9:14 a.m.Denis Maliarevich
May 09 '14, 1:16 a.m.sam detweiler
May 07 '14, 8:29 a.m.