Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How can I determine which JIRA JQL filter uses a specific variable.

Kevin Mahoney October 8, 2018

I have multiple users across my organization's enterprise that use the IssueFunction in linkedIssuesOf(Subquery, [link name]). We've updated our ScriptRunner version that now uses IssueFunction in linkedIssuesOfAll(Subquery, [link name]). 

Is there a way that I can tell what filters in my organization use the old IssueFunction version and or better yet replace those with the new version?

2 answers

1 accepted

1 vote
Answer accepted
Tiffany Wortham
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.
October 17, 2018

This script works for me, but try this on a test instance first to make sure it works as expected for you. Additionally, you'll want to back up your production instance before trying this on there as well just to be sure everything can be recovered if things go south.

That being said, just pop this in the script console, and it should change all of the filters with linkedIssuesOf to linkedIssuesOfAll:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.search.SearchRequest
import com.atlassian.jira.issue.search.SearchRequestEntity
import com.atlassian.jira.issue.search.SearchRequestManager
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.util.Visitor

def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchRequestManager = ComponentAccessor.getComponent(SearchRequestManager)
def userManager = ComponentAccessor.getUserManager()

searchRequestManager.visitAll(new Visitor<SearchRequestEntity>() {
@Override
void visit(SearchRequestEntity searchRequestEntity) {
def requestString = searchRequestEntity.request
if (requestString.contains("linkedIssuesOf(")){

def newRequestString = requestString.replaceAll(~/\blinkedIssuesOf\b\(/, "linkedIssuesOfAll(")

def owner = userManager.getUserByName(searchRequestEntity.author)
def query = jqlQueryParser.parseQuery(newRequestString)
def name = searchRequestEntity.name
def description = searchRequestEntity.description

def newRequest = new SearchRequest(query, owner, name, description, searchRequestEntity.id, searchRequestEntity.favCount)
searchRequestManager.update(newRequest)
}
}
})


Sorry this took me a while, let me know if you have any questions!

3 votes
Andy Heinzer
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 9, 2018

Even if you're a system admin in Jira, you won't be able to see all the filters created by all users.   Only if that user shares the filter with you, can you even see it.

If you're using Jira Server, I think one way to help identify this would be to go to the SQL database for Jira and then use a SQL query to find these filters.  You could do this with a statement such as:

select * from searchrequest where reqcontent like '%linkedIssuesOf%';

on a postgresql database.  The syntax might be slightly different for other database types.  But this would at least help tell you which filters in your Jira instance are using this specific term.

It might be technically possible for you to update these directly via SQL, but I wouldn't recommend making changes to the SQL database directly.  Especially while Jira is running.  It would be safer to make these changes in the Jira web interface one by one.

Brian Spence
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.
November 16, 2018

Thank you, I'm hesitant to do direct DB edits as well.  Appreciate the alternative.  And the fact that we only have ~140 needing edits (and some aren't used anymore) makes me more comfortable.

Suggest an answer

Log in or Sign up to answer