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!
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 :)
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.