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

1 vote
Vasiliy Zverev Community Champion Feb 13, 2016

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
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Thursday in Jira

5 ways you can make the most of Jira Software and Bitbucket Cloud

As part of the Bitbucket product team I'm always interested in better understanding what kind of impact the use of our tools have on the way you work. In a recent study we conducted of software devel...

78 views 0 5
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