Calculating the time duration spent by a work item in a particluar state in javascript
One answer
getWorkFlowAction() also does not tell you that the state is changing. The problem is not detecting the state, it is detecting the change. I think you would have to use an attribute to calculate the current state and store it there. And then use another calculation to detect the state has changes and store the time in another attribute.
The method below won't work as it only works in conditions and it does only indicate that the state might change, but not that it actually changed.
Since 4.0:
since 4.0 M1
getWorkflowAction()
returns a string that is the id of a workflow action currently selected by the user. This action will be executed when the item is saved. If the user has not selected any action this method will return
null
. Note: This method works only when used inside a Condition script, the return value will always be
null
when this is used in other customization script types.
You have way better handling on this in a participant. E.g. see http://rsjazz.wordpress.com/2012/11/27/resolve-parent-if-all-children-are-resolved-participant/
If you want to explore that route, start here: http://rsjazz.wordpress.com/2013/02/28/setting-up-rational-team-concert-for-api-development/
You also would likely need an attribute for every state you want to track.
If others solved this problem, I would be happy to hear about it.
Comments
I have a similar request to this. The scenario is this. A work item is moved to an active state say, working. When the work item is saved then a timestamp is saved into an attribute starttime. When the work item is moved to a non-active state say, delayed or completed. Again a timestamp is saved into an endtime attribute. From this data we can calculate a "duration of active time" and then store that in another attribute total time.
I thought that follow-up actions are not allowed to modify attributes? Since the user would have to click the save button to transition the Work Item from active to non-active and the reverse. How can we get this information? Seems like a catch 22? My other thought was like mentioned above, use Calculated Values Scripts or Conditions Scripts? But like you stated above the user may not change the state of the work item, just save the work item.