Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to retrieve a match string

Caleb Loo January 28, 2015

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

1 vote
Answer accepted
Cesare Jacopo Corzani
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 29, 2015

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

0 votes
Caleb Loo February 17, 2015

Thanks - got the script to work. Much appreciated.

0 votes
Caleb Loo January 29, 2015

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.

Cesare Jacopo Corzani
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 30, 2015

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

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events