It's all about the answers!

Ask a question

Calculating the time duration spent by a work item in a particluar state in javascript

alok Pradhan (612) | asked May 08 '14, 4:28 a.m.
hi ,

I want to calculate the RTC time spent by workitem in a particular state ,but I am not using  any reporting framework, I have to do it using the query and javascript. Please advise on the same

One answer

permanent link
Ralph Schoon (62.0k33643) | answered May 08 '14, 4:47 a.m.
edited May 08 '14, 4:48 a.m.
I am not sure this is possible today. At least, it is not easy. You can not detect a state change easily with Java Script. We did a workshop around JavaScript: Lab 5.

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

If you want to explore that route, start here:

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.

Robert Carter commented Jul 23 '14, 9:39 a.m.

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.

Your answer

Register or to post your answer.