Script runner for Jira upgrade from 2.1.14 to 3.1.4

Hi Team,


We were using the JIRA 6.2.7  with the script runner plugin version 2.1.17 and testing the JIRA version upgrade to 6.4.8 with script runner 3.1.4, but couldnt get the new scripts while scanning from UI in Script JQL Functions section, tried putting the scripts in <jira_home/scripts>, <\jira-home\scripts\com\onresolve\scriptrunner\canned\jira\workflow\postfunctions> and also in <\jira-home\scripts\com\onresolve\jira\groovy\groovyrunner> but the script is not added while scanning, even couldnt find any errors regarding this in the JIRA log file.

Kindly let me know if I am doing it correctly.



1 answer

Hi Jamie,

Locating the script at jira-home\scripts\com\onresolve\jira\groovy\jql and implementing  com.onresolve.jira.groovy.jql.JqlQueryFunction also didnt help us to scan the scripted JQL function.


Please find the below script which we are using and kindly let me know if any more changes are required.


package com.onresolve.jira.groovy.jql
import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.jql.operand.QueryLiteral
import com.atlassian.jira.jql.query.QueryCreationContext
import com.atlassian.jira.util.MessageSet
import com.atlassian.query.clause.TerminalClause
import com.atlassian.query.operand.FunctionOperand
import com.onresolve.jira.groovy.jql.AbstractScriptedJqlFunction
import org.apache.lucene.index.Term
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.user.util.UserUtil
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.ComponentManager
import com.atlassian.crowd.embedded.api.Group;
import com.atlassian.jira.user.ApplicationUser;

class ReportersInSubQueryAndAssigneeWasInCustomGroup  extends AbstractScriptedJqlFunction implements JqlQueryFunction {
    def String subquery
    def String customGroupFieldName
	def reporterliterals = []
	def reporterlist = []
	def groupliterals = []
	def groupList = []
    MessageSet validate(User user, FunctionOperand operand, TerminalClause terminalClause) {
        def messageSet = super.validate(user, operand, terminalClause)
        subquery = operand.args[0]
        customGroupFieldName = operand.args[1]
        // if your function is slow, you might want to limit the results here
        messageSet.addMessageSet (validateSubquery(user, subquery))
     * Implement this method for using datatype = anything but IssueFunction
     * Delete it otherwise
     * @param queryCreationContext
     * @param operand
     * @param terminalClause
     * @return list of query literals
    List&lt;QueryLiteral&gt; getValues(QueryCreationContext queryCreationContext, FunctionOperand operand, TerminalClause terminalClause) {
        ComponentManager componentManager = ComponentManager.getInstance()
		CustomFieldManager customFieldManager = componentManager.getCustomFieldManager()
		def groupManager = ComponentAccessor.getGroupManager()
		ApplicationUser appUser = ComponentAccessor.getJiraAuthenticationContext().getUser();
		User user = appUser.getDirectoryUser();
		String currUserFullName = user.getDisplayName();
		String currUserName = user.getName();      
		def List&lt;String&gt; currentUserGroups = groupManager.getGroupNamesForUser(currUserName);
		log.error (currUserFullName);
		log.error (currUserName);
		subquery = operand.args[0]
        customGroupFieldName = operand.args[1]  
        log.error "subquery : " + subquery
        log.error "Custom Group Field Name : " + customGroupFieldName        
		CustomField customField = customFieldManager.getCustomFieldObjectByName(customGroupFieldName);
        def List&lt;Issue&gt; issues = getIssues(subquery)
		def String groupName
		def String reporterName
		issues.each {Issue issue -&gt; 
		   if(!(issue.reporter == null)){
				  reporterName =
				  if(!(reporterName ==  reporterlist.find {it == reporterName } )){
		   reporterName = ""	
		//groupList.each{ gName -&gt; groupliterals.add(new QueryLiteral(operand, gName as String))}
		currentUserGroups.each{ gName -&gt; groupliterals.add(new QueryLiteral(operand, "'"+ gName + "'" as String))}
		currentUserGroups.each{gName -&gt; log.error gName}
		reporterlist.each{ rName -&gt; reporterliterals.add(new QueryLiteral(operand, rName as String))}
        def foundCustomGroups = groupliterals.join(',')
		def foundReporters = reporterliterals.join(',')
		//log.error "Found Custom Groups : " + foundCustomGroups
        subquery = "reporter in (" + foundReporters + ")" + " AND '" + customGroupFieldName +"' IN ("+foundCustomGroups+")"
		issues = getIssues(subquery)
	    def literals = []
		issues.each {Issue issue -&gt;
                literals &lt;&lt; new QueryLiteral(operand, as Long)




It needs the getDataType method, which you can see at the bottom of In your case you want to return JiraDataTypes.ISSUE

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Feb 07, 2019 in Marketplace Apps

A Timeless Love Story

It started as any story starts, on a normal, rainy day.   Admin meets App, and her name was Klok2, and like any first relationship we were both trying to make it work but neither one knew what...

446 views 8 26
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you