Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Scripted Field to return portfolioChildrenOf

Jamie Rogers
Contributor
March 21, 2024

Greetings

I am needing assistance creating a scripted field to return the results of children issues from our roadmap plans, basically the inverse of "Parent Link" field. We can query this via JQL and it returns the correct results for a given issue key using the portfolioChildrenOf issueFunction (ScriptRunner JQL function).

Example JQL: issueFunction in portfolioChildrenOf("issue in (AJJ-322)"

This returns children issues (epics in this case) of the issue key which is a feature, above epic in our plan hierarchy.

Below is the script code I have tried to implement but it is not returning any results ; its throwing what appears to be a JQL parsing error (also listed below). I am hoping someone can assist or advise what might be happening in my script or aid with a solution. Thanks.

 


SCRIPTED FIELD CODE:

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter

def issueManager = ComponentAccessor.getIssueManager()
def searchService = ComponentAccessor.getComponent(SearchService.class)
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser.class)

def issue = issueManager.getIssueObject(issue.key)
def jqlQuery = jqlQueryParser.parseQuery("issueFunction in portfolioChildrenOf('" + issue.key + "')")

def searchResults = searchService.search(user, jqlQuery, PagerFilter.getUnlimitedFilter())

return searchResults.getResults().size()

ERROR FROM LOGS:
2024-03-22T15:55:07,087 ERROR [jql.ScriptedFunctionClauseFactory]: Error in ScriptRunner JQL function clause {issueFunction in portfolioChildrenOf(AJJ-322)} com.atlassian.jira.jql.parser.JqlParseException: com.atlassian.jira.jql.parser.antlr.RuntimeRecognitionException: NoViableAltException(-1@[]) at com.atlassian.jira.jql.parser.DefaultJqlQueryParser.parseClause(DefaultJqlQueryParser.java:110) ~[classes/:?] at com.atlassian.jira.jql.parser.DefaultJqlQueryParser.parseQuery(DefaultJqlQueryParser.java:33) ~[classes/:?] at com.atlassian.jira.jql.parser.JqlQueryParser$parseQuery$14.call(Unknown Source) ~[?:?] at com.onresolve.jira.groovy.jql.AbstractScriptedJqlFunction.search(AbstractScriptedJqlFunction.groovy:211) ~[plugin.4110092473777456710.groovyrunner-8.22.0.jar:8.22.0] at com.onresolve.jira.groovy.jql.AbstractScriptedJqlFunction$search$0.callCurrent(Unknown Source) ~[?:?] at com.onresolve.jira.groovy.jql.relations.portfolio.PortfolioChildrenOf.getQuery(PortfolioChildrenOf.groovy:28) ~[plugin.4110092473777456710.groovyrunner-8.22.0.jar:8.22.0] at com.onresolve.jira.groovy.jql.JqlQueryFunction$getQuery.call(Unknown Source) ~[?:?] at com.onresolve.jira.groovy.jql.ScriptedJqlFunction.getQuery(ScriptedJqlFunction.groovy:135) ~[plugin.4110092473777456710.groovyrunner-8.22.0.jar:8.22.0] at com.onresolve.jira.groovy.jql.ScriptedJqlFunction$getQuery.call(Unknown Source) ~[?:?] at com.onresolve.jira.groovy.jql.ScriptedFunctionClauseFactory.getQuery(ScriptedFunctionClauseFactory.groovy:110) ~[plugin.4110092473777456710.groovyrunner-8.22.0.jar:8.22.0] Caused by: com.atlassian.jira.jql.parser.antlr.RuntimeRecognitionException: NoViableAltException(-1@[]) at com.atlassian.jira.jql.parser.antlr.JqlParser.reportError(JqlParser.java:203) ~[classes/:?] at com.atlassian.jira.jql.parser.antlr.JqlParser.operator(JqlParser.java:1362) ~[classes/:?] at com.atlassian.jira.jql.parser.antlr.JqlParser.terminalClause(JqlParser.java:645) ~[classes/:?] at com.atlassian.jira.jql.parser.antlr.JqlParser.notClause(JqlParser.java:555) ~[classes/:?] at com.atlassian.jira.jql.parser.antlr.JqlParser.andClause(JqlParser.java:432) ~[classes/:?] at com.atlassian.jira.jql.parser.antlr.JqlParser.orClause(JqlParser.java:366) ~[classes/:?] at com.atlassian.jira.jql.parser.antlr.JqlParser.clause(JqlParser.java:328) ~[classes/:?] at com.atlassian.jira.jql.parser.antlr.JqlParser.query(JqlParser.java:237) ~[classes/:?] at com.atlassian.jira.jql.parser.DefaultJqlQueryParser.parseClause(DefaultJqlQueryParser.java:103) ~[classes/:?] ... 9 more Caused by: org.antlr.runtime.NoViableAltException at com.atlassian.jira.jql.parser.antlr.JqlParser.operator(JqlParser.java:1192) ~[classes/:?] at com.atlassian.jira.jql.parser.antlr.JqlParser.terminalClause(JqlParser.java:645) ~[classes/:?] at com.atlassian.jira.jql.parser.antlr.JqlParser.notClause(JqlParser.java:555) ~[classes/:?] at com.atlassian.jira.jql.parser.antlr.JqlParser.andClause(JqlParser.java:432) ~[classes/:?] at com.atlassian.jira.jql.parser.antlr.JqlParser.orClause(JqlParser.java:366) ~[classes/:?] at com.atlassian.jira.jql.parser.antlr.JqlParser.clause(JqlParser.java:328) ~[classes/:?] at com.atlassian.jira.jql.parser.antlr.JqlParser.query(JqlParser.java:237) ~[classes/:?] at com.atlassian.jira.jql.parser.DefaultJqlQueryParser.parseClause(DefaultJqlQueryParser.java:103) ~[classes/:?] ... 9 more

1 answer

1 accepted

2 votes
Answer accepted
Fabio Racobaldo _Herzum_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 22, 2024

Hi @Jamie Rogers ,

portfolioChildrenOf() function requires a subquery as parameter (https://docs.adaptavist.com/sr4js/latest/features/jql-functions/included-jql-functions/portfolio)

Example :

issueFunction in portfolioChildrenOf("status = 'To Do'")

 

Try to update your code from :

def jqlQuery = jqlQueryParser.parseQuery("issueFunction in portfolioChildrenOf('" + issue.key + "')")

to

def jqlQuery = jqlQueryParser.parseQuery("issueFunction in portfolioChildrenOf(\"issuekey in('" + issue.key + "')\")")

Please let me know if it works,

Fabio

Jamie Rogers
Contributor
March 22, 2024

Thanks this fixed the issue.

I did have 'issue in (issue_key)' in the JQL (which makes sense why it worked there) but didn't realise this was missing in the code ;(

Always good to get a second pair of eyes across these things, so much appreciated!

Fabio Racobaldo _Herzum_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 25, 2024

you're welcome @Jamie Rogers 

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
9.12.4
TAGS
AUG Leaders

Atlassian Community Events