Forums

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

[Scriptrunner] Days an issue has been in current status

taxgaming August 27, 2019

I have the following code:

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.history.ChangeItemBean;
import com.atlassian.jira.issue.Issue;
import com.atlassian.core.util.DateUtils;

def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()

//Create a list of all statuses I want to check against

def statusList = ["Open","In Progress","On Hold","Resolved","Re-open","Blocked"] //All the statuses I want to include
def createdDateDiff = System.currentTimeMillis() - issue.getCreated().getTime() //Time between creation and now - Change
List<Long> rt = [0L]

rt << createdDateDiff

def changeItems = changeHistoryManager.getChangeItemsForField(issue, "status")
changeItems.reverse().each {ChangeItemBean item -> item.fromString

// Get the time passed since status change
def timeDiff = System.currentTimeMillis() - item.created.getTime() // THIS NEEDS TO CHANGE TO FIND LAST STATUS CHANGE TIME

// If the status change left our status, we want to subtract the time passed since then
if (statusList.contains(item.toString)) {
rt << -timeDiff
}

// If the status change goes to our status, we want to add the time passed since then
if (statusList.contains(item.toString)) {
rt << timeDiff
}
}

//converting to days from milliseconds
def newRT = rt as long []
def total = newRT.sum()/ 1000 as long
return DateUtils.getDurationString(total)



Two problems I have:

a) I don't understand where to get information about the 'issue' methods I can use. I've looked here but it doesn't break down the methods https://docs.atlassian.com/software/jira/docs/api/7.2.1/com/atlassian/jira/issue/Issue.html#getCreated-- 

Where do I get more complete information for the libraries and methods?

b) Relating specifically to the code block above, instead of item.created.getTime(), I need to find the last time the issue changed into one of the statuses in the defined list. Then, I can show how many days it's been in that status. 

Hope that makes sense!

 

1 answer

0 votes
David Fischer
Community Champion
August 28, 2019

Side note: you could also use JMCF's Time in Status custom field type, which would not require any coding and would also support searching and statistics gadgets. 

Disclaimer: we are the vendor behind JMCF :)

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events