You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
Hi,
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.
I'm running
JIRA Service Desk 3.8.4
JIRA Core 7.5.3
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
Brad
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.