Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

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;
        }
    });
}) ();

2

1 vote

Comments

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.


Accepted answer

Permanent link
 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

2 votes

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

Your answer

Register or log in to post 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,936

Question asked: Dec 04 '12, 8:07 a.m.

Question was seen: 8,185 times

Last updated: Sep 19 '14, 2:35 a.m.

Confirmation Cancel Confirm