Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
badges earned

Your Points Tracker
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Calculate total time this issue has been In a specific Status and store in custom field


I'm trying to calculate total time this issue has been In a specific Status and store in custom field. I have been reading the forums and it seems like there are add ons that will provide graphs for specific time frames and issues but I need to save it in a custom field. 

I have seen there is a function in script runner to calculate this but it doesn't work in my current environment it shows 2 errors. I have no training in Grovvy scripting so i'm not sure where to put the status values i want to search on. 


Code I'm trying to use is;

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.history.ChangeItemBean

def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()

def inProgressName = "In Progress"

List<Long> rt = [0L]
def changeItems = changeHistoryManager.getChangeItemsForField(ITSD-4807, "status")
changeItems.reverse().each { ChangeItemBean item ->
def timeDiff = System.currentTimeMillis() - item.created.getTime()
if (item.fromString == inProgressName) {
rt << -timeDiff
if (item.toString == inProgressName){
rt << timeDiff

def total = rt.sum() as Long
return (total / 1000) as long ?: 0L


Errors I receive are attached.SRErr1.pngSRErr2.png



I'm running

JIRA Service Desk 3.8.4

JIRA Core 7.5.3


2 answers

1 accepted


Hi Brad! 

The errors that you are seeing are static type checking errors, which mean that they (usually) aren't affecting the functionality of the code. There is more information here, but it basically happens because the inline editor is looking for Java code instead of Groovy code. 

To make this script work, you'll want to go to the Script Fields page -> Add New Item -> Custom Script Field. Give it a name (like "Time in Status"), change the Template to "Duration," copy and paste the script into the inline script field, and click "Add." Next, you'll need to change the Searcher to "Duration Searcher." You can do this by clicking on the Searcher link under your newly created Script Field and then choosing "Duration Searcher" in the Search Template box. Lastly, you'll need to choose which screens you want this field to show up on. You can do this by clicking on the gear icon next to the newly created Script Field and clicking on "Configure Screens."

You should be all set with your Scripted Field! Note that this field will first show up when you transition an issue into the "In Progress" status. It will persist after it transitions out of this status, but it won't show up when you first create the issue. 

Hi Carmen,

Thank you so much for your Reply, This is now working in my JIRA instance and the in progress is being tracked. However I'm actually trying to track the Status  "PENDING RESOURCE" as shown in the attached screenshot. Where do I edit this code to update the status I want to track?

Thanks again


Hi Brad,

To track a different status, simply go back to the Script Field you created and edit this line of code: 

def inProgressName = "In Progress"

Just put whatever status you want inside the quotation marks. This is the only thing you need to change for the code to have the functionality that you want.  

Hi Carmen,

Thanks :) I have updated the status i need and it works when the status is first transition into then out of but then the field disappears. Is it possible to have this show all the time?

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Marketplace Apps & Integrations

Staying organized with Jira: best practices for a better project management

Project managers know this problem: A “mountain of work” lays in front of you, and you don’t know how and where to tackle them. Different to-dos lie ahead, but just one task after the other can be ha...

222 views 2 1
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you