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

Accepted Answer
1 vote

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
Community showcase
Posted Oct 11, 2018 in Marketplace Apps

You + one app + a desert island...

Hi all! My name is Miles and I work on the Marketplace team. We’re looking for better ways to recommend and suggest apps that are truly crowd favorites, so of course we wanted to poll the Community. ...

2,070 views 5 6
Join discussion

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