How to get ApplicationUser object for parseQuery using Listener

We are trying to write a script that parses a string into a JQL query, but it's not working:

parseQuery(ApplicationUser searcher, String query)


import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.user.util.UserUtil;
import com.atlassian.crowd.embedded.api.User;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.util.ImportUtils;
import com.onresolve.scriptrunner.runner.util.UserMessageUtil;
import com.atlassian.query.Query;
import com.atlassian.jira.util.MessageSet;
import com.atlassian.jira.user.ApplicationUser;

def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser);
def searchProvider = ComponentAccessor.getComponent(SearchProvider);
def issueManager = ComponentAccessor.getIssueManager();
SearchService searchService = ComponentAccessor.getComponent(SearchService.class);

UserUtil userUtil = ComponentAccessor.getUserUtil();
ApplicationUser user = ComponentAccessor.getUserManager().getUserByKey("jira-admin");

def query = "project=HELP and created >= -5m";
def query2 = "project=TAG";

SearchService.ParseResult parseResult = SearchService.parseQuery(user, query);
SearchService.ParseResult parseResult2 = SearchService.parseQuery(user, query2);

SearchResults helpTicketList =, parseResult.getQuery(), PagerFilter.getUnlimitedFilter());
SearchResults tagTicketList =, parseResult2.getQuery(), PagerFilter.getUnlimitedFilter());


1 answer

Hi Angela,

I have simplified your script (I optimised your imports, removed unused variables and moved it down to getting just one query working).

package examples

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.web.bean.PagerFilter

SearchService searchService = ComponentAccessor.getComponent(SearchService.class)
ApplicationUser user = ComponentAccessor.getUserManager().getUserByName("admin")

def query = "project=HELP and created >= -5m"

SearchService.ParseResult parseResult = searchService.parseQuery(user, query)
SearchResults helpTicketList =, parseResult.getQuery(), PagerFilter.getUnlimitedFilter())

One major issue I corrected was on the line where you call parseQuery. You were making a static call with SearchService.parseQuery when you should have been calling it on your implementation searchService.parseQuery.

Tip: In Groovy you don't need semi-colons to end a line.

The script I have provided will run and return a result.

Thank you that helps. I noticed this doesn't work in Jira 6.4.3 and Scriptrunner but it works with Jira 7

I'm glad that I was able to help :-) Do you need this to work for Jira 6.4.3? If so are you getting any errors??

HI Stephen,


How can the script authCtxInternal.setLoggedInUser(com.atlassian.jira.user.ApplicationUser) made to work in Jira 6.4?


I tried com.atlassian.jira.user.ApplicationUser.getDirectoryUser(). Is that right?




Suggest an answer

Log in or Sign up to answer
Community showcase
Published Wednesday in Marketplace Apps

Marketplace Spotlight: Marketing apps for Confluence to keep your teams working on the same page


116 views 0 3
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