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

Next challenges

Recent achievements

  • Global
  • Personal


  • Give kudos
  • Received
  • Given


  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Compare Fix Version/s to Affects Version/s in JQL/Scriptrunner


Using JQL I'd like to be able to perform a query sort of like this:

project in (project1, project2) AND affectedVersion != fixVersion

Of course, this query doesn't work. I'd like to know how to compare the Affects Version field to the Fix Version field in JQL. My company's got ScriptRunner, which from what I can gather is required to do this kind of query.

Is there a builtin method in ScriptRunner that will do this kind of comparison? I know that the:

issueFunction in expression(....)

won't do it. 

If not, what's the best way to go about making a custom issueFunction to compare these fields? I tried following these examples, but don't have much experience in Groovy unfortunately.

Thanks so much for your help!

1 answer

1 accepted

0 votes
Answer accepted

So, here's what worked for me. Your mileage may vary, of course.

Examples are hard to find for scriptrunner, so this took a bit.

Forgive the trash-tier spacing, it didn't want to paste correctly.


package com.onresolve.jira.groovy.jql

import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.jql.query.QueryCreationContext
import com.atlassian.jira.jql.validator.NumberOfArgumentsValidator
import com.atlassian.jira.util.MessageSet
import com.atlassian.query.clause.TerminalClause
import com.atlassian.query.operand.FunctionOperand

import java.text.SimpleDateFormat
import java.util.Calendar

import groovy.json.JsonSlurper
import groovy.util.logging.Log4j

import org.apache.commons.httpclient.UsernamePasswordCredentials
import org.apache.commons.httpclient.auth.BasicScheme
import org.apache.http.HttpResponse
import org.apache.http.client.HttpClient
import org.apache.http.impl.client.DefaultHttpClient
import org.apache.http.client.methods.HttpGet
import org.apache.lucene.index.Term

import java.text.MessageFormat

class PullRequestStatus extends AbstractScriptedJqlFunction implements JqlQueryFunction {

String getDescription() {
"Get Issues By Pull Request Status"

MessageSet validate(ApplicationUser user, FunctionOperand operand, TerminalClause terminalClause) {
def messageSet = new NumberOfArgumentsValidator(1, 1, getI18n()).validate(operand)

if (messageSet.hasAnyErrors()) {
return messageSet

messageSet.addMessageSet(validateSubquery(user, operand.args[0]))

List<Map> getArguments() {
description: "Subquery",
optional: false,

String getFunctionName() {

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

def booleanQuery = new BooleanQuery()
def issues = getIssues(operand.args[0], queryCreationContext.applicationUser)

issues.each {Issue issue ->
def affectedVersions = issue.getAffectedVersions()
def fixVersions = issue.getFixVersions()

if(affectedVersions.size() > 0 && fixVersions.size() > 0)
def affectVersion = affectedVersions[0].getName()
def fixVersion = fixVersions[0].getName()

if (affectVersion != fixVersion)
booleanQuery.add(new TermQuery(new Term("issue_id", as String)), BooleanClause.Occur.SHOULD)

return booleanQuery




Suggest an answer

Log in or Sign up to answer

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you