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
Community Members
Community Events
Community Groups

How do I bulk edit saved filters in ScriptRunner?

We have a custom field called "Team" and it has single select values [Team A, Team B, Team C etc].

Team A decides to change their name to Team A-1. It's not a problem to edit the custom field values in the Jira admin settings, and all the issues gets updated. But all saved filters that still uses jql "Team = 'Team A'" does not get changed when the custom field value is edited.

I'm trying to get a script to run on Console that will first find all saved filters that contains "Team = Team A". Then, print the results to show the filter owner, query string, and filter name.

Then, the second run, get all those filters and update the string to be "Team = Team A-1".

But the code I run won't make the replaceAll changes. I'm using custom field ID in case I want to reuse this script for another custom field.


import com.atlassian.jira.bc.JiraServiceContextImpl
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.bc.filter.SearchRequestService
import java.lang.StringBuffer
import java.lang.StringBuilder
import com.atlassian.jira.jql.parser.JqlQueryParser

SearchRequestService searchRequestService = ComponentAccessor.getComponent(SearchRequestService.class)
UserSearchService userSearchService = ComponentAccessor.getComponent(UserSearchService)
def sb = new StringBuffer()
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)

UserSearchParams userSearchParams = new UserSearchParams.Builder()

//iterate over each user's filters
userSearchService.findUsers("", userSearchParams).each{ApplicationUser filter_owner ->
try {
searchRequestService.getOwnedFilters(filter_owner).each{SearchRequest filter->
String jql = filter.getQuery().toString()
def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(10800)//using ID if need to reuse this script for another field
def oldJQL = customField = A as String
def newJQL = customField = A-1 as String
def context = new JiraServiceContextImpl(filter_owner)
if (jql.contains(oldJQL) {
//jql.replaceAll(oldJQL, newJQL) //commented out because still not working
sb.append("Found: ${filter_owner.displayName}, ${}, ${filter.getPermissions().isPrivate() ? 'Private' : 'Shared'}, ${jql}\n")
} catch (Exception e) {
//if filter is private
sb.append("Unable to get filters for ${filter_owner.displayName} due to ${e}")

//output results
return sb.toString()

Any suggestions?

Side question: is something like this possible using REST API? Any guidance on that?

1 answer

0 votes


First i think the best option it to communicate about this change and let the owners make the change themselves.

But you can use the API to get all filter


Then, get the owner to send them a message if the JQL match the customfield or update the filter by your own.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Jira

Online AMA this week: Your project management questions answered by Jira Design Lead James Rotanson

We know that great teams require amazing project management chops. It's no surprise that great teams who use Jira have strong project managers, effective workflows, and secrets that bring planning ...

184 views 1 6
Read article

Atlassian Community Events