Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Using JQL filters in ScriptRunner - Possible? How?

Using JQL filters in ScriptRunner - Possible? How?

Is it possible (if so how) to use JQL queries from Jira in ScriptRunner?  Or, does one have to learn yet another language?  I'm hoping to access existing filters in Jira from ScriptRunner.  Specifically attempting to fix a large number of tickets that have an open Resolution status ( a scenario I/we inherited).

 

Thnx for the insight!

1 answer

0 votes
Payne Community Leader Jun 23, 2021

Sure, you can run any JQL, including a filter, in a ScriptRunner script:

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.issue.MutableIssue
import com.atlassian.jira.issue.search.SearchResults
import com.atlassian.jira.user.util.UserUtil
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.web.bean.PagerFilter

//Put your JQL query here
String jqlSearch = "filter = 'BR Insurance Issues'"

SearchService searchService = ComponentAccessor.getComponent(SearchService.class)
UserUtil userUtil = ComponentAccessor.getUserUtil()
ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
IssueManager issueManager = ComponentAccessor.getIssueManager()
List<MutableIssue> issues = null
SearchService.ParseResult parseResult = searchService.parseQuery(user, jqlSearch)
if (parseResult.isValid()) {
SearchResults searchResult = searchService.search(user, parseResult.getQuery(), PagerFilter.getUnlimitedFilter())
issues = searchResult.getResults().collect {issueManager.getIssueObject(it.id)}
} else {
log.error("Invalid JQL: " + jqlSearch);
}

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you