Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to populate a custom field select list with multiple choices

I am creating a new issue via a script in scriptrunner. I am trying to populate a customfield select list with 2 options, I not sure what I need to do to set custom field values to populate the 2 options  in this code, any help would be great.


def location = customFieldManager.getCustomFieldObjectByName("Location")

def fieldConfigLocation = location.getRelevantConfig(issue)
def optionLocation = optionsManager.getOptions(fieldConfigLocation).getOptionForValue(["ODC, RDC"], null)
issue.setCustomFieldValue(location, [optionLocation])

1 answer

Hi @Karina Green 

Try below code to populate Select list field value according to issue type selection :-

Please make sure value which you want to populate must be added in select list field.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.*


def issuetype = getIssueContext().getIssueType().name


def selectcf = getFieldByName("Sub-type")
selectcf.setFormValue(null)

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def optionsManager = ComponentAccessor.getOptionsManager()
def customField = customFieldManager.getCustomFieldObject(selectcf.getFieldId())
def config = customField.getRelevantConfig(getIssueContext())
def options = optionsManager.getOptions(config)


if (issuetype.contains("Story")) {
def optionsMap = options.findAll {
it.value in ["Custom Requests","Survey Project Management","Proposals"]
}.collectEntries {
[
(it.optionId.toString()): it.value
]
}
selectcf.setFieldOptions(optionsMap)
}
else {
def optionsMap = options.findAll {
it.value in ["Job Matching Assistance Only", "Standard Data Extract","Job Matching and Data Extract","Prevailing Wage"]
}.collectEntries {
[
(it.optionId.toString()): it.value
]
}
selectcf.setFieldOptions(optionsMap)


}

I forget to add classes :- 

Correct Script --

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.atlassian.jira.issue.customfields.manager.OptionsManager

import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours


def issuetype = getIssueContext().getIssueType().name


def selectcf = getFieldByName("Sub-type")
selectcf.setFormValue(null)

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def optionsManager = ComponentAccessor.getOptionsManager()
def customField = customFieldManager.getCustomFieldObject(selectcf.getFieldId())
def config = customField.getRelevantConfig(getIssueContext())
def options = optionsManager.getOptions(config)


if (issuetype.contains("Story")) {
def optionsMap = options.findAll {
it.value in ["Custom Requests","Survey Project Management","Proposals"]
}.collectEntries {
[
(it.optionId.toString()): it.value
]
}
selectcf.setFieldOptions(optionsMap)
}
else {
def optionsMap = options.findAll {
it.value in ["Job Matching Assistance Only", "Standard Data Extract","Job Matching and Data Extract","Prevailing Wage"]
}.collectEntries {
[
(it.optionId.toString()): it.value
]
}
selectcf.setFieldOptions(optionsMap)


}

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you