Need to get Multislect Values

Hi,

I need to get the multiselect values which the user has selected using groovy script . Here is what I have done.

CustomField cfRBIENV = customFieldManager.getCustomFieldObjectByName("RBI-Environment")

List<Option> options = (List<Option>)cfRBIENV.getValue(issue);log.warn("Size " + options.size())
for (int i = 1; i <= options.size(); i++) {
Env=options[i].toString() + " " + Env

}

1 answer

This widget could not be displayed.

Hi Pushparaj,

This looks correct except for the loop I would start from i = 0 and go until i < options.size().

I tried it and works fine.

Vijay

Yes but I need only the selected values . SUppose I choose two values 1st and 3rd in the options , it shows the size has 2 , but when I print the values I get the first value , but the second in the options list is null .Hence need to print only the selected value in the multiselect.

Hi Pushparaj,

Here is the script. It gives the selected values.

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.customfields.option.Option
import org.apache.log4j.Logger
import org.apache.log4j.Level

issueManager = ComponentAccessor.getIssueManager()
issueFactory = ComponentAccessor.getIssueFactory()
customFieldManager = ComponentAccessor.getCustomFieldManager()
Env = ""
issue = ComponentAccessor.getIssueManager().getIssueObject("TEST-123")

customFieldManager = ComponentAccessor.getCustomFieldManager()
CustomField cf1= ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Impact Arch. Layer")
Logger log = Logger.getLogger("com.onresolve.jira.groovy.createStreamRequirement")
log.setLevel(Level.DEBUG)

List&lt;Option&gt; options = (List&lt;Option&gt;) issue.getCustomFieldValue(cf1)
log.warn("Size " + options.size())
for (int i = 0; i &lt; options.size(); i++) {
Env=options[i].toString() + " " + Env
log.debug options[i].toString()
}
log.debug Env

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...

232 views 3 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