Scriptruuner groovy date null



Getting null exception 

java.lang.NullPointerException: Cannot invoke method getTime() on null object at java_sql_Timestamp$ Source) at


How com after checking resolution for null date can be null

How can I check for Date null condition

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.jql.builder.JqlClauseBuilder
import com.atlassian.jira.jql.builder.JqlQueryBuilder
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.project.Project

def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()
def projectManager = ComponentAccessor.getProjectManager()
import org.apache.log4j.Category
def Category log = Category.getInstance("")
Project project = ComponentAccessor.getProjectManager().getProjectObjByKey("JPM");
//CustomField customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("");

IssueManager issueManager = ComponentAccessor.getIssueManager();

log.debug ("Key | Created | Resolved | Elapsed")

for(Issue issue: issueManager.getIssueObjects( issueManager.getIssueIdsForProject(project.getId()))){

if ( == "Story")
if ( issue.getResolution() != null ) {
log.debug(issue.getKey()+"|"+ new Date( issue.getCreated().getTime())+ "|"+
new Date(issue.resolutionDate .getTime())
(issue.resolutionDate.getTime() - issue.getCreated().getTime()) / 1000 / 3600 / 24 +" | "+



Also how do I get value from a custom field called "mycustom"


Please let me know




2 answers

1 accepted

1 vote
Accepted answer
Henning Tietgens Community Champion Aug 04, 2017

In case you want to restrict your issues, you should use a search like this.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.web.bean.PagerFilter

SearchService searchService = ComponentAccessor.getComponent(SearchService.class)

def jqlSearch = "project = JPM and created > '2017-05-01'"
List<Issue> issues = null
def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def result = ""

SearchService.ParseResult parseResult = searchService.parseQuery(user, jqlSearch)
if (parseResult.isValid()) {
def searchResult =, parseResult.getQuery(), PagerFilter.getUnlimitedFilter())
issues = searchResult.issues
result += "Found ${issues.size()} issues."
} else {
result += "Invalid JQL: " + jqlSearch


Henning Tietgens Community Champion Aug 04, 2017

For searching for issues created in the last two weeks you could use

project = JPM and created > startOfWeek(-2w)

for the complete last two weeks or

project = JPM and created > -2w

 for exactly the last two weeks.

Thanks for he help Henning.

I have already accepted answer, just a followup question...

Like we use eclipse for java programming which helps with syntax, api suggestions etc what editor to use to develop grrovy scripting.

Iam looking for some thing which can suggest available methods on object, code hlp etc just like clipse.


Is there any editor which can suggest Jira grrovy api while creating a script? What do you use..?


I was looking at

but it looks dated.

Henning Tietgens Community Champion Aug 06, 2017

Just look in the documentation, there is a chapter about setting up a development environment:


0 votes
Henning Tietgens Community Champion Aug 04, 2017

This shouldn't be the case, maybe corrupt data? Try this in the script console:

import com.atlassian.jira.component.ComponentAccessor

def project = ComponentAccessor.projectManager.getProjectObjByKey("JPM")
def issueManager = ComponentAccessor.issueManager
def customFieldManager = ComponentAccessor.customFieldManager

def cf = customFieldManager.getCustomFieldObjectsByName('mycustom').first()

def result = "Key | Created | Resolved | Elapsed | Components | myname<br>"

issueManager.getIssueObjects( issueManager.getIssueIdsForProject(project.getId())).each{ issue ->
if ( == "Story" && issue.resolution) {
def duration
if (issue.resolutionDate) {
duration = (issue.resolutionDate.getTime() - issue.getCreated().getTime()) / 1000 / 3600 / 24
result += "$issue.key|" +
"${issue.getCreated()?.format("YYYY-MM-dd HH:mm:ss")}|"+
"${issue.resolutionDate?.format("YYYY-MM-dd HH:mm:ss")}|" +
"$duration|" +
"${issue.getComponents()*.name?.join(',')}|" +

This also shows you how to get the value of a custom field. In this case I suspect a text field. If it's a different field type, you have to do a little more, like issue.getCustomFieldValue(cf)?.value if it's a select field.


Thanks Henning

it works great.

If I need to look at issues that are created 

- Only after a certain date 

- Only last 2 weeks 

How do I compare dates?

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Oct 31, 2018 in Marketplace Apps

Marketplace Spotlight: Zephyr

Hello Atlassian Community! Each month, we run a series of Spotlights to highlight Marketplace vendors and apps that our team thinks this Community would find valuable. In last month's Spotlig...

412 views 0 3
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you