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 widget could not be displayed.

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

This widget could not be displayed.
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
Atlassian Summit 2018

Meet the community IRL

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

Learn more
Community showcase
Posted Wednesday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

256 views 5 0
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