Are you in the loop? Keep up with the latest by making sure you're subscribed to Community Announcements. Just click Watch and select Articles.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Service not working correctly

Edited

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 

1 answer

Suggest an answer

Log in or Sign up to answer
0 votes
Steven Behnke
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Jun 05, 2018 • edited

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.

TAGS
AUG Leaders

Atlassian Community Events