JQL to return issues selected in a Scriptrunner custom single Issue Picker field?

Anna-Marie Blinn July 8, 2021

I have a Scriptrunner custom single issue picker field "Master" which is used on selected custom issue types to allow users to select from a subset of Epics.  This is used for a slightly different purpose than the built-in Epic field, and I need to have both. 

When using JQL to search for issues, if I use 

issueFunction in issuePickerField('Master')

I get a list of all of the issues where the user has selected something in the Master field.  What I want is to get a list of the issues (Epics) that were selected in that field (like what "epicsOf" returns, except this would be for the Master field, rather than the built-in Epic fields).

Am I missing something? Is there a way to do this with JQL?  (Based on what I read in the Scriptrunner docs, I do not have the skill / knowledge / tools to create my own JQL custom function.)

3 answers

1 accepted

0 votes
Answer accepted
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 12, 2021

Unless I'm misunderstanding something, I don't think the existing function allows that.

I would recommend making a feature request to get the reverse of the current issuePickerField function.

Anna-Marie Blinn July 12, 2021

Thank you, feature request submitted.

0 votes
Alex Trebek November 29, 2022

Ran into the same problem. Ended up with a custom "epicsOf"-like JQL-function:

package com.onresolve.jira.groovy.jql

import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.jql.query.LuceneQueryBuilder
import com.atlassian.jira.jql.query.QueryCreationContext
import com.atlassian.jira.jql.validator.NumberOfArgumentsValidator
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.util.MessageSet
import com.atlassian.query.clause.TerminalClause
import com.atlassian.query.operand.FunctionOperand
import org.apache.lucene.search.Query
import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.util.MessageSetImpl
import com.atlassian.jira.security.JiraAuthenticationContext
import org.apache.lucene.search.BooleanQuery
import com.atlassian.jira.issue.Issue
import org.apache.lucene.search.TermQuery
import org.apache.lucene.index.Term
import org.apache.lucene.search.BooleanClause

import java.text.MessageFormat

class presalesOf extends AbstractScriptedJqlFunction implements JqlQueryFunction {

@Override
String getDescription() {
"Get Presales of issues fetched from query"
}

@Override
List<Map> getArguments() {
[
[
description: "Subquery",
optional : false,
]
]
}

@Override
String getFunctionName() {
"presalesOf"
}


@Override
Query getQuery(QueryCreationContext queryCreationContext, FunctionOperand operand, TerminalClause terminalClause) {

JiraAuthenticationContext context = ComponentAccessor.getJiraAuthenticationContext()
ApplicationUser applicationUser = context.getLoggedInUser()

BooleanQuery.Builder boolQueryBuilder = new BooleanQuery.Builder()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cFieldPresale = customFieldManager.getCustomFieldObjectsByName("Presale").getAt(0)
String queryPrefix = "((Presale is not Empty AND project != PRESALE) OR (FieldName is not Empty AND project = PRESALE AND issueType != Epic))"
String subquery = "${queryPrefix} AND ${operand.args[0]}"
issues = getIssues(subquery, applicationUser)
Collection<Issue> issuesPresales = (issues.findAll { it }*.getCustomFieldValue(cFieldPresale)) as Collection<Issue>
issuesPresales = issuesPresales?.unique()
issuesPresales.each {Issue issue ->
try {
boolQueryBuilder.add(new TermQuery(new Term("issue_id", issue.id as String)), BooleanClause.Occur.SHOULD)
} catch(NullPointerException NPE) {

}
}

return boolQueryBuilder.build()
}

}
0 votes
Avi Bachar September 2, 2021

I am looking for the same solution

have you found a solution for that?

Anna-Marie Blinn September 2, 2021

No solution yet.  It is sitting with Atlassian as a new feature request.

Like Avi Bachar likes this
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 2, 2021

You won't get any traction with an Atlassian feature request.

This is a scriptrunner JQL functionality. 

You need to ask Adaptavist for this: https://productsupport.adaptavist.com/servicedesk

Anna-Marie Blinn September 2, 2021

Apologies, teach me for responding too early my time.  I meant that it's with Adaptavist.

Suggest an answer

Log in or Sign up to answer