Unable to retrieve a match string

HI, I have the following snippet of code via Groovy ScriptRunner.

Issue currIssue = componentManager.getIssueManager().getIssueObject("TESTDEV-712")

def targetVersion = currIssue.getCustomFieldValue(cf)
log.debug targetVersion

def fixVersion = currIssue.getFixVersions()
log.debug fixVersion

fixInHead = fixVersion.grep('HEAD')

log.debug fixInHead

if (fixVersion.contains(targetVersion))
   log.debug "Found match"
   log.debug "No match"


My test data is:

Target Version = 8102

Fix Version = 8102, HEAD

Expected it to return "Found match" but for some unknown reason, it doesn't see the match. Please help! Thanks!

3 answers

1 accepted

target version and fix version are both lists.

I would suggest you to change "contains" to "containsAll"

if (fixVersion.containsAll(targetVersion))
   log.debug "Found match"
   log.debug "No match"

This will work if the target version would be one or multiple selections

Thanks! That works. I have a follow-up question. What's the call that I can make to return the list count? I'm new with groovy scripting.

To retrieve the list count you can use the size() method. So "fixVersion.size()". The answer depends by the purpose of your script. If you are creating a scripted field just take a look at that: https://jamieechlin.atlassian.net/wiki/display/GRV/Scripted+Fields

Thanks - got the script to work. Much appreciated.

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Apr 30, 2018 in Marketplace Apps

Why moving to Confluence Data Center is only a job half-done

Confluence Data Center is a deployment option that was designed for performance at scale. In other words, Confluence will handle increased traffic much reliably in a clustered environment and yo...

249 views 0 6
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