It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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
Answer accepted

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


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.

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


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 in Marketplace Apps & Integrations

Marketplace Spotlight: Manage your assets with asset management apps

  The role of IT professionals has become increasingly difficult over the last decade. Our organizations work in an increasingly software-powered world and IT professionals are expected to not...

262 views 3 9
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you