Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to get 'None' as options in List

Khushbu Jowaheer April 9, 2018

Hello All,

I have 3 custom fields:

1. Team(Select list)
2. Category(Cascading list)
3. Supplier (Select list)

I want to populate Category and Supplier based on team which I have been able to do so. But my problem i'm not able to get the default value 'None' along with the values i want to populate.

Here is what i've been doing so far.
****************************************************************
import com.atlassian.jira.component.ComponentAccessor

//defining variable to get custom fields
def fieldA = getFieldById(getFieldChanged())
def category_Field=getFieldByName("Category_Field")
def supplier_Field=getFieldByName("Supplier_Field")

//Calling the OptionsManager interface to manage option values for field 'Categories'
def optionsManager = ComponentAccessor.getOptionsManager()
def customField = customFieldManager.getCustomFieldObjectByName("Category_Field")
def config = customField.getRelevantConfig(getIssueContext())
def options = optionsManager.getOptions(config)

//Calling the OptionsManager interface to manage option values for field 'Supplier'
def optionsManager1 = ComponentAccessor.getOptionsManager() 
def customField1 = customFieldManager.getCustomFieldObjectByName("Supplier_Field")
def config1 = customField1.getRelevantConfig(getIssueContext())
def options1 = optionsManager1.getOptions(config1)

def selectedOption1 = category_Field.getValue() as String
def selectedOption1= team

if (team == "team1") {

//list of category you want to show

category_Field.setFieldOptions(options.findAll

{it.value in [-1,'category1','category2','category3']}

)

// list of supplier names you want to show
def optionsMap = options1.findAll 

{ it.value in [-1,"value1","value2"] }

.collectEntries

{ [ (it.optionId.toString()) : it.value ] }

supplier_Field.setFieldOptions(optionsMap)
}

else if(team == "team2"){

category_Field.setFieldOptions(options.findAll

{it.value in [-1,'category4', 'category5']}

)

def optionsMap = options1.findAll 

{ it.value in [-1,"value3","value4"] }

.collectEntries

{ [ (it.optionId.toString()) : it.value ] }

supplier_Field.setFieldOptions(optionsMap)

}

else

{ category_Field.setFormValue(null) }

****************************************************************
Please assist.

Thanks,
Khushbu

1 answer

0 votes
Nic Brough -Adaptavist-
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.
April 9, 2018

"None" is not an option.  It is what Jira displays to the user when the field is empty, or to select "field is empty" when they want to clear it.  That's why REST does not report anything - there's nothing really there!

To "select" none, don't put anything in the field.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events