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 Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Thursday in Jira

Meet the AUG leaders of Northern Virginia

@Rachel Wright (Jira Genie), @Billy Poggi (AUG NOVA, DC), and @Dana Jansen (Confluence Queen) are just some of the folks that lead one of the world's most active Atlassian User Group (AUG)....

121 views 4 9
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