Unable to search issues in groovy as a service

Hi,

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")
log.setLevel(org.apache.log4j.Level.INFO)
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
Community showcase
Published Oct 31, 2018 in Marketplace Apps

Marketplace Spotlight: Zephyr

Hello Atlassian Community! Each month, we run a series of Spotlights to highlight Marketplace vendors and apps that our team thinks this Community would find valuable. In last month's Spotlig...

335 views 0 1
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