Hi all,
I have a radio button field on which I want to hide the None-option.
I have read through a lot of posts saying that I should use Scriptrunners Behaviours. So, I created a behaviour, added a Initializor and this is where I get stuck. How do I remove the None-option? Anyone who has done this and has some working example to share? I really need some help here.
Best regards
Mattias
Hi Mattias,
I think you can just collect all of the options for a field and then use the setFieldOptions method to set the options for the field. When all the options for a field are collected, I believe that "None" will automatically be excluded, so "None" will no longer be a choice after setting the options for the field.
I've not tested this, but it should look something like this:
import com.atlassian.jira.component.ComponentAccessor
//Grab appropriate managers
def cfManager = ComponentAccessor.getCustomFieldManager()
def optionsManager = ComponentAccessor.getOptionsManager()
//Grab form and custom field values
def selectCF = cfManager.getCustomFieldObject("SelectListA")
def selectField = getFieldByName("SelectListA")
//Must grab the relevant config given the current issue context and the custom field
def config = selectCF.getRelevantConfig(getIssueContext())
//Given config, grab a map of the possible options for the select custom field
def options = optionsManager.getOptions(config)
//Define preset multi select options for each single select case
selectField.setFieldOptions(options.collectEntries{[(it.optionId): it.value]})
Of course you'll want to change "SelectListA" in this script to the actual name of your field.
Regards,
Josh
Hi Joshua,
Thanks for your script. After a minor change to it (used the field id instead of the field name) it works perfectly. Maybe I have to use id since we have Swedish characters in the field name, not sure. However, this is how thoses lines look now:
…
//Grab form and custom field values
def selectCF = cfManager.getCustomFieldObject("customfield_12345")
def selectField = getFieldById("customfield_12345")
…
Once again, thanks for your help!
Regards
Mattias
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Glad to hear you got it working. Thx for using ScriptRunner!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The script is still working fine - thanks!
Is it also possible to hide entries / elements of a the radio buttons field like "do not show last option of the list"?
Best Regards
Manuel
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Joshua Yamdogo @ Adaptavist
I tried the script you provided. Where do I add the field options? I used the script as is and none still appears to me. Can you please help me with it?
My field options are yes and no.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.