Evaluation of Multi Select with script runner fails

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

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
}

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

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

1 vote
Henning Tietgens Community Champion Jan 26, 2014

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

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 Community Champion Jan 26, 2014

What's the output for

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

?

log.warn cfValues["MyCascadingSelect"]*.value[0].class returned: null

Henning Tietgens Community Champion Jan 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?

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 Community Champion Jan 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 Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,338 views 14 20
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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot