It's all about the answers!

Ask a question

RTC Calculated Value dependent on Status is triggered by any change

Bill Taylor (3144) | asked Dec 04 '12, 8:07 a.m.
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

(function() {
    var WorkItemAttributes =;
    dojo.declare("client.valueProvider.currentInProgressDate", null, {
        getValue: function(attribute, workItem, configuration) {
            var now = Date(), {milliseconds:true, zulu:true});
            var dayZero = 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;
                    case 'taskworkflow.state.s1':                //New
                        if (myOldValue != null) {
                            return dayZero;
            return myOldValue;
}) ();

Brian Fleming commented Dec 04 '12, 9:14 a.m.

Denis Maliarevich commented May 07 '14, 4:56 a.m. | edited 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 commented May 07 '14, 8:29 a.m.

extensions fire on all changes. using  Javascript  there is no info on the prior state.

Accepted answer

permanent link
N Z (3622026) | answered May 09 '14, 1:46 a.m.
 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

Lorena Almela commented Sep 18 '14, 6:12 p.m.


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.

if its the same, no save...

Ralph Schoon commented Sep 19 '14, 2:35 a.m.

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

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:

Your answer

Register or to post your answer.