Forums

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

Combine Scriptrunner Query To Create JQL Filter

Alexander
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
September 21, 2022

I'm sorry, my programming skills are unfortunately not sufficient to connect these two snippets in a meaningful way. Therefore I would be glad about some help.

What is the goal? I have a number of tickets and want to dynamically determine the key with the highest number to use in further JQL queries/dashboards. I want to save this query as a filter.

The first script determines the key, the second saves it as a filter. But here I need a hint how to connect the two.

Many greetings

Alexander

Identifying the key

import ...

def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser

def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchService = ComponentAccessor.getComponent(SearchService)

def jqlSearch = "project = ABC and type = story ORDER BY key DESC"

def query = jqlQueryParser.parseQuery(jqlSearch)
def results = searchService .search(user,query, PagerFilter.getUnlimitedFilter())
results.getResults().first()

Saving as filter

import ...

def searchRequestService = ComponentLocator.getComponent(SearchRequestService)
def user = ComponentAccessor.jiraAuthenticationContext?.getLoggedInUser()
def searchService = ComponentAccessor.getComponent(SearchService)

def serviceContext = new JiraServiceContextImpl(user)

THIS NEEDS TO BE REPLACED WITH THE RESULT ABOVE?

def parseResult = searchService.parseQuery(user, "project = JRA")
if (parseResult.isValid()) {

// create the search request
def query = parseResult.query
def searchRequest = new SearchRequest(query, user, "My filter", "Some description")

// set shares
def sharePerm = new SharePermissionImpl(null, ShareType.Name.GROUP, "jira-administrators", null)
searchRequest.setPermissions(new SharedEntity.SharePermissions([sharePerm] as Set))

// store the search request
searchRequestService.createFilter(serviceContext, searchRequest)
}

1 answer

0 votes
Ram Kumar Aravindakshan _Adaptavist_
Community Champion
October 5, 2022

Hi @Alexander

If you intend to create a JQL Filter via ScriptRunner, you can refer to this ScriptRunner Documentation for more information.

It provides an example of how to do this via the ScriptRunner Console.

I hope this helps to answer your question. :-)

Thank you and Kind regards,

Ram

Suggest an answer

Log in or Sign up to answer