Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Custom Field to show "time in status" in days

Anil Kumar Bondada December 5, 2018

Hello, 

We're trying to create a custom field which can show the "time in current status" in days for  the issues in JIRA. The field has to reset and show the new value(new age) whenever the issue is transitioned.  Is it possible to create such field using scriptrunner? Please let me know if there is any workaround as well. Thanks in Advance

1 answer

0 votes
Jenna Davis
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 6, 2018

Hello Anil, 

I believe the response on this community question contains a script similar to what you're looking for, as well as some instructions on how it should be set up: https://community.atlassian.com/t5/Answers-Developer-Questions/Time-elapsed-in-current-status-Scripted-Field-Date-Time-search/qaq-p/560648

Hopefully that helps to get you started on this!

Let me know if you need further information, or if this worked for you. 

Jenna

Anil Kumar Bondada December 6, 2018

@Jenna Davis Thanks for directing me to a similar discussion. I was able to take the code from that discussiion and apply it. But, looks like I'm getting the result in hours. I've replied in that post as well asking for a correction. Please look the code that I'm using and let me know the changes that are required to get the acurate result in days. Thanks in Advance 

 

code 

import com.atlassian.jira.component.ComponentAccessor

def changeHistoryManager = ComponentAccessor.changeHistoryManager
def currentStatusName = issue?.status?.name

def rt = [0L]
changeHistoryManager.getChangeItemsForField (issue, "status").reverse().each {item ->

def timeDiff = System.currentTimeMillis() - item.created.getTime()
if (item.fromString == currentStatusName) {
rt << -timeDiff
}
if (item.toString == currentStatusName){
rt << timeDiff
}
}
return (Math.round(rt.sum() / 3600000)) as Double
Jenna Davis
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 11, 2018

Sorry for my late reply here! 

In order to get days, you'll need to change the last return line. 'rt.sum()' originally will give you the time in milliseconds, so the rt.sum()/3600000 converts milliseconds to hours. You just need to change that to convert milliseconds to days. I believe you need to change 3600000 to 86400000 in order to achieve this. 

Hope this helps!

Jenna

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events