Hello,
I'm quite new in Scriptrunner, but was trying to script custom field, which shows the duration from issue creation to status 'resolved'.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()
def createDate = issue.getCreated().getTime();
def resolutionDate = issue.getResolutionDate().getTime();
if (resolutionDate == null) {
return null;
}
return (resolutionDate - createDate)/1000 as long;
(Searcher: Duration Searcher
Template: Duration)
Actually the output is correct (see attachment):
but logs sometimes show:
2018-03-30 10:19:57,121 ERROR [customfield.GroovyCustomField]: ********** java.lang.NullPointerException: Cannot invoke method getTime() on null object at Script952.run(Script952.groovy:7)
It's obvious that this error appears only if you're working in open (not resolved) issues.
How the logic should be modified so that the field only "work for" resolved issues?
You should write like this
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
def issue = ComponentAccessor.getIssueManager().getIssueObject("MAV-2")
def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()
def createDate = issue.getCreated().getTime();
def resolutionDate = issue.getResolutionDate()?.getTime();
if (resolutionDate == null) {
return null;
}
return (resolutionDate - createDate)/1000 as long;
This calculates for all the time between created and resolved dates. Is there a way to exclude the times from 5PM to 9AM everyday and also the weekends?
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.
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.