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
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
@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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.