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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,641,243
Community Members
 
Community Events
196
Community Groups

ScriptRunner/Groovy - Retrieve all saved filters and edit them

Hi!

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.

Thanks!

3 answers

1 accepted

2 votes
Answer accepted
Henning Tietgens
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Aug 04, 2017

Hi,

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.

Henning

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)
searchRequestService.getOwnedFilters(user).each{filter->
def nQuery = searcher.parseQuery(user, getNewQuery(filter.getQuery().toString())).getQuery()
filter.setQuery(nQuery)
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 {...}
Henning Tietgens
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Aug 06, 2017

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.bc.user.search.UserSearchParams
import com.atlassian.jira.bc.user.search.UserSearchService
import com.atlassian.jira.component.ComponentAccessor

def userSearchService = ComponentAccessor.getComponent(UserSearchService)
def userSearchParams = new UserSearchParams.Builder()
.allowEmptyQuery(true)
.ignorePermissionCheck(true)
.maxResults(10000)
.build()
def allUsers = userSearchService.findUsers("", userSearchParams)

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

Henning

0 votes
Diana Gorv
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Oct 18, 2022

hi @elie_g 

This might be a long shot, but by any chance could you share your full script? I've been trying to achieve the exact same thing, and follow the suggestions, but no luck. I was hoping to see maybe by each line where mine is wrong in comparison to yours if you still have it?

Thanks!

Like Diana Gorv likes this

Hi @Diana Gorv ,

Unfortunately, I don't work at the same place anymore so I don't have access to the script I had made. However, if you can share your script here maybe I or someone will be able to help you.

Diana Gorv
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Nov 14, 2022

Hi @elie_g  thanks for replying back!

I have my script here in another question: https://community.atlassian.com/t5/Adaptavist-questions/How-do-I-bulk-edit-saved-filters-in-ScriptRunner/qaq-p/2141723

But I had thrown in the towel on this one. Although I was able to identify filters, I can't seem to make bulk edit. My team has decided to manually edit. But if others know, it would be a nice to have at this point.

Thanks!

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events