Scripted field problem

Hi All,

I created a scripted field which calculates the sum of the time spent in Open and In Progress statuses. But in the case when the current status is still In Progress, the field doesn't calculate that time spent: e.g.:

Can you please help what is wrong?

import com.atlassian.core.util.DateUtils
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.history.ChangeItemBean
def componentManager = ComponentManager.getInstance()
def changeHistoryManager = componentManager.getChangeHistoryManager()
def status1Name = "Open"
def status2Name = "In progress"
def time = System.currentTimeMillis()
def rt = [0]
// If one of the status is the very first status in a workflow you have to
// add the creation time to the array because the creation time is not a
// transition that will be counted in the following loop.
// Uncomment the following line if that is so:
rt << time - issue.genericValue.created.getTime()
// Loop through all transitions and catch the times for the specified transition
def ch = changeHistoryManager.getChangeItemsForField (issue, "status")
for (i=0; i<ch.size(); i++) {
   def timeDiff = time - ch[i].created.getTime()
   if (ch[i].fromString == status1Name) { rt << -timeDiff }
   if (ch[i].fromString == status2Name) { rt << -timeDiff }

   if (i<ch.size()-1) {
      if (ch[i].toString == status1Name && ch[i+1].fromString == status1Name) { rt << timeDiff }
      if (ch[i].toString == status2Name && ch[i+1].fromString == status2Name) { rt << timeDiff }
// Return the sum of all array values, formatted as a duration string
Math.round(rt.sum() / 60000).toString()

3 answers

This widget could not be displayed.

Someone else posted an update to this script which they said fixes an issue that sounds similar to yours... didn't test it though.

This widget could not be displayed.

Hi Jamie,

where is that update? In this forum?

I searched the whole forum before I posted..

This widget could not be displayed.

Yep, I thought so. Maybe on the wiki for the plugin then, not sure...

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted yesterday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

46 views 1 0
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you