Hi everyone,
i want to calculate age of issue and have script like that:
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueManager
def issueManager = ComponentAccessor.getIssueManager()
if (issue.status.name == "RESOLVED" && "FAILED" && "CLOSED"){
return (issue.getResolutionDate() - issue.created)*24*60*60
} else {
return (new Date()- issue.created)*24*60*60
}
it calculate great age of opened issue, but i can't calculate age of closed issue, i mean how long was this issue active.
btw. i have 3 fields with Date: Created, Updatet and Resolved. Updated - Created works, Resolved - created not.
I try to define issue status in order for the script to understand in which case to calculate and than date of resolved issue subtract from issue created.
How can i define my status and issue.resolved than subtract it?
We need some clarification.
First of all, the code snippet has some mistakes.
1. issue's status cannot be RESOLVED, FAILED and CLOSED at the same time, so you should change that as below
if (["RESOLVED", "FAILED", "CLOSED"].contains(issue.status.name){
return (issue.getResolutionDate() - issue.created)*24*60*60
}
However, as far as I see, you want to get resolution date if the issue was resolved. So, code below returns time passed till resolution field was changed.
if (null != issue.resolution) {
return (issue.getResolutionDate() - issue.created)*24*60*60
}
2. The next problem is to get the closed date. As far as I understand you want to calculate time between created till the issue's status changes as CLOSED. Unfortunately, Jira does not give that value out-of-the-box. You have to find it programatically or you need to use an app.
Below code gives you the date that issue was closed.
def changeHistoryManager = componentManager.getChangeHistoryManager()
def closedDate = changeHistoryManager.getChangeItemsForField(issue, "status").find{it.equals("CLOSED")}?.created
On the other hand, you can also use an app to get those values without bothering with scripts.
Enhancer Plugin has Time Between custom field, in which you can easily find time passed between any statuses or events. Please note that, I'm one of the folks behind Snapbytes, and there might be other solutions on Atlassian Marketplace as well.
I hope I was helpful.
Please let me know if I could not understand your question clearly.
Tuncay
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.