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.
Working scripted field for me (thanks for @PD Sheehan):
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.issue.Issue
def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def 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)
This script should work for that:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.jql.parser.JqlQueryParser
def jql= "project = $issue.projectObject.key and reporter = $user.name and resolution is empty"
def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchService = ComponentAccessor.getComponent(SearchService)
def query = jqlQueryParser.parseQuery(jql)
searchService.searchCount(user,query)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 created
com.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 more
Caused by: MismatchedSetException(64!=null)
at com.atlassian.jira.jql.parser.antlr.JqlLexer.recover(JqlLexer.java:135)
... 18 more
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
What version of Jira are you using?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Can you paste your full script?
I have this working on 7.13.2 and 8.3.2
But I had to make a quick change, make sure the "def user=" line is above the "def jql=" line.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.issue.Issue
def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def jql= "project = PROJ and reporter = $issue.reporter.name and resolution is empty"
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchService = ComponentAccessor.getComponent(SearchService)
def query = jqlQueryParser.parseQuery(jql)
searchService.searchCount(user,query)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Not sure where to go from here...
I copied your script exactly and all I changed was the project key in the jql... and that works for me.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I maked fresh install latest jira service desk, dont changed any settings, installed scriprunner, truing make script field and get same trouble, script wont work for me. Sad.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Could you explain "script won't work for me"? What are the error messages or results, and what are you doing differently to what Peter-Dave has done?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Fresh install. Jira 8.4.1, Adaptavist ScriptRunner for JIRA v. 5.6.2.1-jira8
Log:
2019-09-28 18:44:53,112 ERROR [runner.ScriptFieldPreviewRunner]: *************************************************************************************
2019-09-28 18:44:53,113 ERROR [runner.ScriptFieldPreviewRunner]: Script field preview failed for field that has not yet been created
com.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 Script7.run(Script7.groovy:10)
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 more
Caused by: MismatchedSetException(64!=null)
at com.atlassian.jira.jql.parser.antlr.JqlLexer.recover(JqlLexer.java:135)
... 18 more
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Looks like the query parser doesn't like the JQL that we generate.
Let's try to add some debug message.
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.issue.Issue
def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser
log.debug "Reporter name is: ${issue.reporter?.name}"
//I think name and username are supposed to be the same, but let's be sure
log.debug "Reporter Username is: ${issue.reporter?.username}"
def jql= "project = TEST and reporter = $issue.reporter.name and resolution is empty"
log.debug "JQL is: $jql"
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchService = ComponentAccessor.getComponent(SearchService)
def query = jqlQueryParser.parseQuery(jql)
searchService.searchCount(user,query)
Then post the logs (before the error) and also, paste the JQL exactly as it appears int he log into your Jira Issue Navigator and show us what it renders.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for idea with logs! Working jql for me is:
def jql = "project = TEST and reporter = '$issue.reporter.name' and resolution is empty"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.