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
4,365,871
Community Members
 
Community Events
168
Community Groups

Combine Scriptrunner Query To Create JQL Filter

Alexander I'm New Here Sep 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)
}

0 answers

Suggest an answer

Log in or Sign up to answer