RTC Calculated Value dependent on Status is triggered by any change
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
Comments
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,
as NZ mentions, you save the state ONLY when u care, but check it every time.
if its the same, no save...
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.
The trick with a hidden attribute is the only one I am aware of. Another way is using a participant, which would however issue a second save.
If you disagree with the implementation as it is, please create an enhancement request here: https://jazz.net/jazz/web/projects/Rational%20Team%20Concert#action=com.ibm.team.workitem.viewWelcome
Comments
Brian Fleming
Dec 04 '12, 9:14 a.m.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
Denis Maliarevich
May 09 '14, 1:16 a.m.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.
sam detweiler
May 07 '14, 8:29 a.m.extensions fire on all changes. using Javascript there is no info on the prior state.