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.issue.search.SearchProvider import com.atlassian.jira.jql.parser.JqlQueryParser import com.atlassian.jira.web.bean.PagerFilter import com.atlassian.jira.issue.link.IssueLinkTypeManager 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.atlassian.jira.issue.search.*; import com.atlassian.jira.bc.issue.search.SearchService; 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 = searchService.search(user, parseResult.getQuery(), PagerFilter.getUnlimitedFilter()); SearchResults tagTicketList = searchService.search(user, parseResult2.getQuery(), PagerFilter.getUnlimitedFilter());
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.bc.issue.search.SearchService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.search.SearchResults
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 = searchService.search(user, 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 4.1.3.24 but it works with Jira 7
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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??
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
Thanks
Shilpa
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.