Can this be done via a Jira query? I need to do this for multiple incidents.
Hi @Surbhi Jain
This is not possible natively with Jira automatically.
You'll need to look into an add-on or even some SQL if you have more powerful reporting capability.
ScriptRunner for Jira will be able to achieve what you need in a scripted custom field.
PowerScripts for Jira I am not 100% sure that Power Scripts has similar functionality but it would be worth checking out both options.
I believe there might also be a gadget you could use on a dashboard Resolution Time might be useful for you as well.
Aah OK. Looks like I will need to reach out to our Jira admin to get a custom field created.
import com.atlassian.core.util.DateUtilsDateUtils.getDurationString(((new Date().getTime() - issue.getCreated().time) / 1000) as Long)
This will get you the time since the ticket was created ^^
The below should get the time of how long each ticket was in status.
//Required Importsimport com.atlassian.core.util.DateUtilsimport com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.issue.history.ChangeItemBeanimport com.atlassian.jira.issue.Issue// Get a pointer to the Change History Managerdef changeHistoryManager = ComponentAccessor.changeHistoryManager// Ensure that the script field does not store cached values and always dynamically re calculates the values every time a page is laoded.enableCache = {-> false}// Define the statuses to report on belowdef status1 = "Workflow Status"def status2 = "Status"def status3 = "Status"def status4 = "Status"def status5 = "Status"def status6 = "Status"def status7 = "Status"def status8 = "Status"// Get a pointer to the current issuedef issue = issue as Issue// Get the Suspect timeList<Long> rt1 = [0L]changeHistoryManager.getChangeItemsForField (issue, "status").reverse().each {ChangeItemBean item ->def timeDiff = System.currentTimeMillis() - item.created.getTime()if (item.fromString == status1) {rt1 << -timeDiff}if (item.toString == status1){rt1 << timeDiff}}// Get the Step 2 TimeList<Long> rt2 = [0L]changeHistoryManager.getChangeItemsForField (issue, "status").reverse().each {ChangeItemBean item ->def timeDiff = System.currentTimeMillis() - item.created.getTime()if (item.fromString == status2) {rt2 << -timeDiff}if (item.toString == status2){rt2 << timeDiff}}// Get the Step 3 TimeList<Long> rt3 = [0L]changeHistoryManager.getChangeItemsForField (issue, "status").reverse().each {ChangeItemBean item ->def timeDiff = System.currentTimeMillis() - item.created.getTime()if (item.fromString == status3) {rt3 << -timeDiff}if (item.toString == status3){rt3 << timeDiff}}// Get the Step 4 TimeList<Long> rt4 = [0L]changeHistoryManager.getChangeItemsForField (issue, "status").reverse().each {ChangeItemBean item ->def timeDiff = System.currentTimeMillis() - item.created.getTime()if (item.fromString == status4) {rt4 << -timeDiff}if (item.toString == status4){rt4 << timeDiff}}// Get the Step 5 TimeList<Long> rt5 = [0L]changeHistoryManager.getChangeItemsForField (issue, "status").reverse().each {ChangeItemBean item ->def timeDiff = System.currentTimeMillis() - item.created.getTime()if (item.fromString == status5) {rt5 << -timeDiff}if (item.toString == status5){rt5 << timeDiff}}// Get the Step 6 TimeList<Long> rt6 = [0L]changeHistoryManager.getChangeItemsForField (issue, "status").reverse().each {ChangeItemBean item ->def timeDiff = System.currentTimeMillis() - item.created.getTime()if (item.fromString == status6) {rt6 << -timeDiff}if (item.toString == status6){rt6 << timeDiff}}// Get the Step 7 TimeList<Long> rt7 = [0L]changeHistoryManager.getChangeItemsForField (issue, "status").reverse().each {ChangeItemBean item ->def timeDiff = System.currentTimeMillis() - item.created.getTime()if (item.fromString == status7) {rt7 << -timeDiff}if (item.toString == status7){rt7 << timeDiff}}// Get the Step 8 TimeList<Long> rt8 = [0L]changeHistoryManager.getChangeItemsForField (issue, "status").reverse().each {ChangeItemBean item ->def timeDiff = System.currentTimeMillis() - item.created.getTime()if (item.fromString == status8) {rt8 << -timeDiff}if (item.toString == status8){rt8 << timeDiff}}// Return times for each status// NOTE: doesn't show anything if less than 60 secondsdef status1Time = DateUtils.getDurationString(Math.round((rt1.sum().toString().toDouble() / 1000) as Double)) ?: "0m" as Stringdef status2Time = DateUtils.getDurationString(Math.round((rt2.sum().toString().toDouble() / 1000) as Double)) ?: "0m" as Stringdef status3Time = DateUtils.getDurationString(Math.round((rt3.sum().toString().toDouble() / 1000) as Double)) ?: "0m" as Stringdef status4Time = DateUtils.getDurationString(Math.round((rt4.sum().toString().toDouble() / 1000) as Double)) ?: "0m" as Stringdef status5Time = DateUtils.getDurationString(Math.round((rt5.sum().toString().toDouble() / 1000) as Double)) ?: "0m" as Stringdef status6Time = DateUtils.getDurationString(Math.round((rt6.sum().toString().toDouble() / 1000) as Double)) ?: "0m" as Stringdef status7Time = DateUtils.getDurationString(Math.round((rt7.sum().toString().toDouble() / 1000) as Double)) ?: "0m" as Stringdef status8Time = DateUtils.getDurationString(Math.round((rt8.sum().toString().toDouble() / 1000) as Double)) ?: "0m" as Stringreturn " Workflow Status = " + status1Time + "<br/>"+ " Workflow Status = " + status2Time + "<br/>"+ " Workflow Status = " + status3Time + "<br/>"+ " Workflow Status = " + status4Time + "<br/>"+ " Workflow Status = " + status5Time + "<br/>"+ " Workflow Status = " + status6Time
This would benefit me greatly, but I'm new to Jira (SD) so... how do you integrate the above into Jira SD? i.e. do you need to add that into a custom field etc etc
Explain it like I'm 5 :P
I have a tool I developed using Google Sheets that does what you need. It will pull the data from Jira and automatically calculate time in status along with quite a few other metrics. Here is my blog post explaining the tool.
I was pretty happy to find this, unfortunately, I wasn't able to get this working in a reasonable amount of time either. Looking for other options now.
Hi @Brittany Wispell
thanks
It looks like you're new here. Sign in or register to get started.