Set checkbox options based on a select list

I have written many behaviours to do what I've asked above, however, I haven't tried to do it with checkboxes, I've only done this to set the options for a select list.

What I have is a single select list field (Field A). Depending on the option selected in Field A, I need a checkbox field (Field B) to populate with a subset of the total options in the checkbox field.

My code is below, can someone PLEASE help with this. I'm not sure if there's a different convention for working with checkboxes/multi-selects.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.util.UserUtil

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def optionsManager = ComponentAccessor.getOptionsManager()

def cf1 = getFieldByName("Select List")
def cf2 = getFieldByName("CheckBox")

def cf1Val = cf1.getValue().toString()

cf2.setHidden(true)

def customField = customFieldManager.getCustomFieldObject(cf2.getFieldId())
def config = customField.getRelevantConfig(getIssueContext())
def options = optionsManager.getOptions(config)

if(cf1 == "Option 1"){
cf2.setHidden(false)
cf2.setRequired(true)
def optionsMap = options.findAll {
it.value in ["Option 1", "Option 2", "Option 3"] 
}.collectEntries {
[
(it.optionId.toString()) : it.value
]
}

cf2.setFieldOptions(optionsMap)
}

 Thank you in advance!

Nick

0 answers

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
Posted 11 hours ago in Confluence

Calling all marketing teams who use Confluence - we want to hear from you!

Hi Community! me again 🙂 If you’re a marketing team using Confluence, we want to hear your story! How did you start using Confluence? What are your use cases? What have been some of the benefits?...

41 views 1 2
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