I need assistance in creating a scripted field using Scriptrunner to count the number of open issues by reporter of current issue.
Thank you for any help.
This script should work for that:
import com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.bc.issue.search.SearchServiceimport com.atlassian.jira.jql.parser.JqlQueryParserdef jql= "project = $issue.projectObject.key and reporter = $user.name and resolution is empty"def user = ComponentAccessor.jiraAuthenticationContext.loggedInUserdef jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)def searchService = ComponentAccessor.getComponent(SearchService)def query = jqlQueryParser.parseQuery(jql)searchService.searchCount(user,query)
Working scripted field for me (thanks for @PD Sheehan):
import com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.bc.issue.search.SearchServiceimport com.atlassian.jira.jql.parser.JqlQueryParserimport com.atlassian.jira.issue.Issuedef user = ComponentAccessor.jiraAuthenticationContext.loggedInUserdef jql = "project = $issue.projectObject.key and reporter = '$issue.reporter.name' and statusCategory != Done"def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)def searchService = ComponentAccessor.getComponent(SearchService)def query = jqlQueryParser.parseQuery(jql)searchService.searchCount(user,query)
Thank you for example, but i have trouble with it. I need jql like this:
def jql= "project = 123 and reporter = $issue.reporter and resolution is empty"
but when i use this jql i get result "null". I trying some variants: $issue.getReported(), $issue.reporter.getEmailAddress() - still not work. When i remove "reporter = ... " script work fine. When i put "issue.reporter" in the end of script - i get reporter, work fine. I get error when use "reporter = $issue.reporter" in jql.
What am i doing wrong?
Try
def jql= "project = 123 and reporter = $issue.reporter.name and resolution is empty"
BTW, if you want to include a more complex method with parens like "getEmailAddress()" you have to enclose the expression in curly brace.
What happens is the that $simple.expression or ${complex.getExpression()} ins the Gstring will be extrapolated when it gets coerced to a String when callling the parseQuery
"${issue.getEmailAddress()}" is equivalent to "$issue.emailAddress"
Thanks for information. Still not working, get error in log:
2019-09-27 02:00:14,024 ERROR [runner.ScriptFieldPreviewRunner]: *************************************************************************************2019-09-27 02:00:14,024 ERROR [runner.ScriptFieldPreviewRunner]: Script field preview failed for field that has not yet been createdcom.atlassian.jira.jql.parser.JqlParseException: com.atlassian.jira.jql.parser.antlr.RuntimeRecognitionException: MismatchedSetException(64!=null)at com.atlassian.jira.jql.parser.DefaultJqlQueryParser.parseClause(DefaultJqlQueryParser.java:110)at com.atlassian.jira.jql.parser.DefaultJqlQueryParser.parseQuery(DefaultJqlQueryParser.java:33)at Script168.run(Script168.groovy:12)Caused by: com.atlassian.jira.jql.parser.antlr.RuntimeRecognitionException: MismatchedSetException(64!=null)at com.atlassian.jira.jql.parser.antlr.LexerErrorHelper.handleError(LexerErrorHelper.java:48)at com.atlassian.jira.jql.parser.antlr.JqlLexer.recover(JqlLexer.java:130)at com.atlassian.jira.jql.parser.antlr.JqlLexer.recover(JqlLexer.java:136)at com.atlassian.jira.jql.parser.antlr.JqlLexer.mERROR_RESERVED(JqlLexer.java:1921)at com.atlassian.jira.jql.parser.antlr.JqlLexer.mTokens(JqlLexer.java:2684)at org.antlr.runtime.Lexer.nextToken(Lexer.java:85)at org.antlr.runtime.BufferedTokenStream.fetch(BufferedTokenStream.java:143)at org.antlr.runtime.BufferedTokenStream.sync(BufferedTokenStream.java:137)at org.antlr.runtime.CommonTokenStream.skipOffTokenChannels(CommonTokenStream.java:113)at org.antlr.runtime.CommonTokenStream.LT(CommonTokenStream.java:102)at org.antlr.runtime.BufferedTokenStream.LA(BufferedTokenStream.java:174)at com.atlassian.jira.jql.parser.antlr.JqlParser.operand(JqlParser.java:1696)at com.atlassian.jira.jql.parser.antlr.JqlParser.terminalClause(JqlParser.java:672)at com.atlassian.jira.jql.parser.antlr.JqlParser.notClause(JqlParser.java:555)at com.atlassian.jira.jql.parser.antlr.JqlParser.andClause(JqlParser.java:451)at com.atlassian.jira.jql.parser.antlr.JqlParser.orClause(JqlParser.java:366)at com.atlassian.jira.jql.parser.antlr.JqlParser.clause(JqlParser.java:328)at com.atlassian.jira.jql.parser.antlr.JqlParser.query(JqlParser.java:237)at com.atlassian.jira.jql.parser.DefaultJqlQueryParser.parseClause(DefaultJqlQueryParser.java:103)... 2 moreCaused by: MismatchedSetException(64!=null)at com.atlassian.jira.jql.parser.antlr.JqlLexer.recover(JqlLexer.java:135)... 18 more
It looks like you're new here. Sign in or register to get started.