Hi
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.bc.issue.search.SearchService
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.setLevel(org.apache.log4j.Level.DEBUG)
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);
if(parseResult.isValid()){
log.debug("inside parse if")
def searchResult = searchService.search(user, parseResult.getQuery(), PagerFilter.getUnlimitedFilter());
issues = searchResult.issues.collect {issueManager.getIssueObject(it.id)
log.debug(issues)
issues.each(){
log.debug("inside loop")
def estField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(11401)
def cFieldValue = issues.getCustomFieldValue(estField)
log.debug(cFieldValue)
if ( cFieldValue == 0.0) {
def subject = "${issues.key} has no Estimate"
def body = "https://b13technology.atlassian.net/issue/${issues.key} \n This issue does not have an estimate"
def emailAddr = "b13bot@b13technology.com"
SMTPMailServer mailServer = ComponentAccessor.getMailServerManager().getDefaultSMTPMailServer()
if (mailServer) {
Email email = new Email(emailAddr);
email.setSubject(subject);
email.setBody(body.toString());
mailServer.send(email);
log.debug("Mail sent")
}
else {
log.debug("Please make sure that a valid mailServer is configured")
}
}
}
}
}
else{
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] groovyService.run
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 = searchService.search(user, parseResult.getQuery(), PagerFilter.getUnlimitedFilter());
issues = searchResult.issues.collect {issueManager.getIssueObject(it.id)
I really hope someone is able to help with this issue, it has held be up for a while.
Many thanks
Tyler
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.