Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

Service not working correctly




So i have refactored my code since i last posted a question on here to see if i could get it working better my self (i hope anyhow)


I manage to find a log of where this code was executing and crashing.

Below is my code 


import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.CustomFieldManager
import java.util.logging.Logger
import com.atlassian.mail.Email
import com.atlassian.mail.server.MailServerManager
import com.atlassian.mail.server.SMTPMailServer
import com.atlassian.jira.component.ComponentAccessor
import org.apache.log4j.Category
import com.atlassian.jira.user.util.UserUtil
import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.web.bean.PagerFilter

def Category log = Category.getInstance("com.onresolve.jira.groovy")
log.debug("start of code")

jqlSearch = 'updated >= -4w'; // Create the JQL query to perform
theUser = "jira_bot"; // Specify the user that should execute the query if not logged in

SearchService searchService = ComponentAccessor.getComponent(SearchService.class);
UserUtil userUtil = ComponentAccessor.getUserUtil();
User user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();

// If the user isn't specified, then set it to the default script running user
if (!user) {
user = userUtil.getUserObject(theUser);
// Set the default list of issues to null just to be safe
List<Issue> issues = null;

// Perform the search as a user and return the result so it can be validated.
SearchService.ParseResult parseResult = searchService.parseQuery(user, jqlSearch);

log.debug("inside parse if")
def searchResult =, parseResult.getQuery(), PagerFilter.getUnlimitedFilter());
issues = searchResult.issues.collect {issueManager.getIssueObject(
log.debug("inside loop")
def estField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(11401)
def cFieldValue = issues.getCustomFieldValue(estField)
if ( cFieldValue == 0.0) {
def subject = "${issues.key} has no Estimate"
def body = "${issues.key} \n This issue does not have an estimate"
def emailAddr = ""
SMTPMailServer mailServer = ComponentAccessor.getMailServerManager().getDefaultSMTPMailServer()

if (mailServer) {
Email email = new Email(emailAddr);
log.debug("Mail sent")
else {
log.debug("Please make sure that a valid mailServer is configured")
log.error("Invalid JQL: " + jqlSearch);

 Below is my log


2018-06-06 02:05:37,233 https-jsse-nio-443-exec-68 INFO tyler 125x18592x1 oui304 xxxxxxx /secure/admin/ViewServices!default.jspa [c.o.jira.groovy.GroovyService] groovyService.init : input-file=D:\Atlassian\scripts\logerror.groovy
2018-06-06 02:05:37,236 https-jsse-nio-443-exec-68 INFO tyler 125x18592x1 oui304 xxxxxxx /secure/admin/ViewServices!default.jspa [c.o.jira.groovy.GroovyService] groovyService.init : input-file=D:\Atlassian\scripts\IHNE.groovy
2018-06-06 02:10:00,002 Caesium-1-1 INFO anonymous no estimate - send email [c.o.jira.groovy.GroovyService]
2018-06-06 02:10:02,471 Caesium-1-1 DEBUG anonymous no estimate - send email [c.onresolve.jira.groovy] start of code
2018-06-06 02:10:02,489 Caesium-1-1 DEBUG anonymous no estimate - send email [c.onresolve.jira.groovy] inside parse if


There is no logging under "inside parse if" which gives the indication that the service does not like this section

def searchResult =, parseResult.getQuery(), PagerFilter.getUnlimitedFilter());
issues = searchResult.issues.collect {issueManager.getIssueObject(


I really hope someone is able to help with this issue, it has held be up for a while.


Many thanks


1 answer

Likely, the user you're searching with has no permissions to see issues -- the list of issues is EMPTY, so the loop is never entered, so nothing is logged within the loop.

Suggest an answer

Log in or Sign up to answer

Atlassian Community Events