Evaluation of Multi Select with script runner fails

Mathias L. January 23, 2014

Maybe its only due to Friday afternoon why I don't see the error, but why does the following code return false instead of true?

assert cfValues['MyMultiSelect']*.value.contains("Test")
       |       |                    |     |
       |       [null:Test, 1:Test]  |     false
       |                            [Test, Test]

2 answers

1 accepted

2 votes
Answer accepted
Mathias L. January 27, 2014

This seems to work now. customfield_10119 and Test are the variables to be defined ;-)

Thanks Henning.

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.customfields.impl.CascadingSelectCFType

 
ComponentManager componentManager = ComponentManager.getInstance()
CustomFieldManager customFieldManager = componentManager.getCustomFieldManager()
CustomField cf= customFieldManager.getCustomFieldObject("customfield_10109")
issue = componentManager.getIssueManager().getIssueObject(issue.id)

def value = issue.getCustomFieldValue(cf)
 
def parentValueA = value[CascadingSelectCFType.PARENT_KEY]
def childValueA = value[CascadingSelectCFType.CHILD_KEY]

if (parentValueA.value=='Test' || childValueA.value=='Test') {
    return true
} else {
    return false
}

Mathias L. January 27, 2014

And to make a long story short - this also seems to do the trick:

cfValues['MyCascadingSelect']*.value.value.contains("Test")

1 vote
Henning Tietgens
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 26, 2014

Did you check the class of the elements in cfValues['MyMultiSelect']*.value?

Mathias L. January 26, 2014

I might have been not precise enough in my original question. It is a Cascading Select custom field. Actually I was currently already looking at that:

assert cfValues['MyCascadingSelect'].class
       |       |                   |
       |       [null:Test, 1:Test] null

It returns "null" for the class. Some additional help would be very welcome.

Henning Tietgens
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 26, 2014

What's the output for

assert cfValues['MyMultiSelect']*.value[0].class

?

Mathias L. January 26, 2014
log.warn cfValues["MyCascadingSelect"]*.value[0].class returned: null

Henning Tietgens
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 26, 2014

Mmh.

I use

def value = issue.getCustomFieldValue(cfA)  // which should be the same as cfValues['CS Field A']
def parentValueA = value[CascadingSelectCFType.PARENT_KEY]
if (parentValueA) {
    def childValueA = value[CascadingSelectCFType.CHILD_KEY]
    //...
}

to access the content of a cascading select field. Could you try this?

Mathias L. January 26, 2014

Entering this in the script console

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.customfields.impl.CascadingSelectCFType

ComponentManager componentManager = ComponentManager.getInstance()
CustomFieldManager customFieldManager = componentManager.getCustomFieldManager()
CustomField cf= customFieldManager.getCustomFieldObject("customfield_10109") 
issue = componentManager.getIssueManager().getIssueObject("xxxx-651")

log.warn cf.class

log.warn "-----------------------"

def value = issue.getCustomFieldValue(cf)

def parentValueA = value[CascadingSelectCFType.PARENT_KEY]
if (parentValueA) {
    def childValueA = value[CascadingSelectCFType.CHILD_KEY]
    //...
    log.warn "Test parentValueA: " + parentValueA
    log.warn "Test childValueA: " + childValueA
}

returns the expected results (test , test) and

class com.atlassian.jira.issue.fields.CustomFieldImpl

Does this help to build the condition?

Henning Tietgens
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 26, 2014

I think so :-) You could than check both values for "Test".

if (parentValueA=='Test' || childValueA=='Test') {
    return true
} else {
    return false
}

You could enter the whole code as a condition, your are not restricted to one row.

Suggest an answer

Log in or Sign up to answer