Unable to search issues in groovy as a service


I have written a below groovy script which is rendering issues in Script Console but not in GroovyService.

It shows Total issues >> 0 as a service

but shows Total issues >> 23 issues in Script Console.

Please correct me if I went somewhere wrong or do I need to modify script ?

import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.user.util.UserUtil
import com.atlassian.jira.web.bean.PagerFilter
import org.apache.log4j.Category
import java.util.List;

def log = Category.getInstance("com.onresolve.jira.groovy.example.IssueIteration")
jqlSearch = "project = Agile"
SearchService searchService = ComponentAccessor.getComponent(SearchService.class)
UserUtil userUtil = ComponentAccessor.getUserUtil()
User user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
IssueManager issueManager = ComponentAccessor.getIssueManager()
def List<Issue> issues = null 

SearchService.ParseResult parseResult =  searchService.parseQuery(user, jqlSearch)
if (parseResult.isValid()) 
    def searchResult = searchService.search(user, parseResult.getQuery(), PagerFilter.getUnlimitedFilter())
     issues = searchResult.getIssues();
	 log.info "Total issues >> "+searchResult.getTotal()
		issues.each{issue ->
			log.info "Issue is "+issue
 else {
    log.error("Invalid JQL: " + jqlSearch );

1 answer

Resolved by

def searchResult = searchService.search(ComponentAccessor.getUserManager().getUserByName("admin").getDirectoryUser(), parseResult.getQuery(), PagerFilter.getUnlimitedFilter())

Yeah, there's no "logged in user" when a service runs.

That's why I was wondering that script runs in console but not in service :)

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Jul 10, 2018 in Marketplace Apps

If you’re an Atlassian app developer, you’ll want to know about Atlas Camp!

This September 6-7, hundreds of Atlassian App developers will flock to Barcelona Spain to build skills, discover product roadmaps, meet face-to-face with the Atlassian team, and learn how to extend t...

158 views 0 4
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