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

This widget could not be displayed.

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
Community showcase
Published Aug 22, 2018 in Marketplace Apps

How a Marketplace app tech team is achieving gender diversity

Hello! My name is Genevieve Blanch, and I'm the Marketing Manager at RefinedWiki, creators of apps to give teams the tools to customize Atlassian platforms. Currently, 44% of the tech team at Re...

463 views 3 17
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