ScriptRunner/Groovy - Retrieve all saved filters and edit them


I would like to know if it is possible to retrieve all saved filters and edit each of them using a function like collect or each.


1 answer

1 accepted

2 votes
Accepted answer


yes by using the SearchRequestService (ComponentAccessor.getComponent(SearchRequestService)) you can retrieve filers, update and delete them.

If you want to retrieve all filters existing in the system you first have to retrieve all users (using the UserManager or UserUtil) and then retrieve all filters of each user using SearchRequestService.getOwnedFilters(). For the SearchRequest elements of the result you can use SearchRequest .query.queryString to get the JQL query. You can modify the SearchRequest and use SearchRequestService.updateFilter() to save the modifications.


Thanks Henning!

With your help I've been able to update filters of a single user but I don't know how to retrieve all the users. I look at the methods of UserUtils and UserManager but the getAllUsers function is deprecated. Moreover, the description of getAllUser says that it retrieve the users I need, but I need all users without any exceptions.

So I assume I need to retrieve all users using JQL query but I dont have any idea of what JQL query would do the job.

Do you know how I can retrieve all the users?

This is what I've done so far:

def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def ctx = new JiraServiceContextImpl(user)
def nQuery = searcher.parseQuery(user, getNewQuery(filter.getQuery().toString())).getQuery()
searchRequestService.updateFilter(ctx, filter)

Nevermind I got it!

Using the global group, I did this to retrieve all users:

ComponentManager.getGroupManager().getUsersInGroup('jira-core-users').each {...}

Yes, that's a possibility if you have a group with all users. If it's a one-time job, you could use deprecated methods, too. Deprecated means you should replace this method in your code because it may go away in future releases. Or you could use the UserSearchService:

import com.atlassian.jira.component.ComponentAccessor

def userSearchService = ComponentAccessor.getComponent(UserSearchService)
def userSearchParams = new UserSearchParams.Builder()
def allUsers = userSearchService.findUsers("", userSearchParams)

Just use a number higher than the number of your user for maxResults.


Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 29, 2018 in Marketplace Apps

How to set up an incident workflow from the VP of Engineering at Sentry

Hey Atlassian community, I help lead engineering at Sentry, an open-source error-tracking and monitoring tool that integrates with Jira. We started using Jira Software Cloud internally last year, a...

1,709 views 3 11
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