Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Removing the 'None' option from select fields

David Harkins
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 31, 2023

I had a requirement to remove the None option from several fields, to increase screen estate and make the display screens more graceful.

Quite a few answers out there which also match the same mechanism being used here, ScriptRunner Behaviours.  However most answers I found required the script author to explicitly list the values that should be displayed.  While this does achieve the same end goal it is getting all options excluding none, not actually removing none.

What happens if me or a future system admin adds additional options to the fields, they will not show and the behaviours will have to hunted down, modified, and tested.  Additionally, if we wanted to do this with multiple fields, the script can become lengthy and prone to human typos.  We've all done it.

My solution has started as a simple behaviour script to remove 'none' from three fields with less lines of scripts and will not require modification when new options are added.

The current script is:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.customfields.manager.OptionsManager

hideNone("Field 1")
hideNone("Field 2")
hideNone("Field 3")

def hideNone(String FieldName){
    def optionsManager = ComponentAccessor.getComponent(OptionsManager)
    def field = getFieldByName(FieldName)
    def fieldId = customFieldManager.getCustomFieldObject(field.getFieldId())
    def fieldConfig = fieldId.getRelevantConfig(getIssueContext())
    def fieldOptionsOriginal = optionsManager.getOptions(fieldConfig)
    def fieldOptionsCustYes = fieldOptionsOriginal.findAll { it.value !in ["none"] }
    field.setFieldOptions( fieldOptionsCustYes )
The next step will be to create a helper class script so that the same hideNone method can be used on multiple behaviour scripts whenever it is needed, without having to duplicate the same lines of code.
Just wanted to share and help others :-)

1 comment

Nadeem Zakir February 20, 2024

Thanks for the above, I tried it on Jira Data Centre but didnt seem to work.  We only have one field for now but none still shows up.  Any help appreciated.


Log in or Sign up to comment
AUG Leaders

Atlassian Community Events