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"
else
   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

This widget could not be displayed.

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"
else
   log.debug "No match"

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

This widget could not be displayed.

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

This widget could not be displayed.

Thanks - got the script to work. Much appreciated.

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Published Jul 25, 2018 in Marketplace Apps

Jira Cloud and Bitbucket Cloud Integration with Microsoft Teams

One of the newest products in the Microsoft family - Microsoft Teams,  is a chat-based hub for teamwork that integrates all the people, content, and tools your team needs to be more engaged and ...

718 views 0 3
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