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
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published Apr 19, 2018 in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

366 views 0 6
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