Find filter dependencies before deleting a filter

Is there a way to find filter dependencies without having to search in the Database so that I can safely delete a filter?

i.e. I want to ensure

  1. The filter I want to delete, is not used by other filters
  2. Is not used in a dashboard
  3. Has no subscriptions
  4. Is not used in an Agile Board
  5. Is not used in other plugins

1 answer

1 accepted

I use this code to get all subscriptions via Script console of ScriptRunner:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.subscription.FilterSubscription
import com.atlassian.jira.issue.subscription.SubscriptionManager

StringBuilder result = new StringBuilder();
SubscriptionManager subscriptionManager = ComponentAccessor.getSubscriptionManager();
for(FilterSubscription subscription: subscriptionManager.getAllFilterSubscriptions()){
    result.append("{ " + subscription.getLastRunTime().toString() + " / " + subscription.getFilterId() + " }")
}

return result.toString()

And this one to get all filters:

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.search.SearchRequest;
import com.atlassian.jira.issue.search.SearchRequestManager;
import com.atlassian.jira.sharing.SharePermission;
import com.atlassian.jira.user.ApplicationUser;
import com.atlassian.jira.user.util.UserUtil;

ArrayList<String> Filters = new ArrayList<String>();
UserUtil userUtil = ComponentAccessor.getUserUtil();
SearchRequestManager searchRequestManager = ComponentAccessor.getComponent(SearchRequestManager.class);
ArrayList<SearchRequest> FilterList;
String CurFilter = "";
boolean HasGlobal;
String CurPerm;
for(ApplicationUser CurUser: (ArrayList<ApplicationUser>) userUtil.getAllApplicationUsers())
{
    FilterList = (ArrayList<SearchRequest>) searchRequestManager.getAllOwnedSearchRequests(CurUser);
    for (SearchRequest Search: FilterList)
    {
        CurFilter = Search.getName() + "#" + Search.getQuery() + "/" + Search.getOwnerUserName() + "#";

        HasGlobal = false;

        for (SharePermission Perm: Search.getPermissions().getPermissionSet())
        {
            CurPerm = Perm.getType().get();
            CurFilter += CurPerm + "/" + Perm.getParam1() + "/" + Perm.getParam2() + "#";

            if (CurPerm == "global")
                HasGlobal = true;
        }

        CurFilter += " \n"
        if (!Filters.contains(CurFilter))
            if (HasGlobal)
            {
                Filters.add(CurFilter);
            }
    }
}
String Result = "";
for (String Filter: Filters)
{
    Result += Filter + "\n@";
}
return Result

Try to modify these ones for your needs

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Julia Dillon
Posted Tuesday in Jira

Tell us how your team runs on Jira!

Hey Atlassian Community! Today we are launching a bunch of customer stories about the amazing work teams, like Dropbox and Twilio, are doing with Jira. You can check out the stories here. The thi...

244 views 1 18
Join discussion

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