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
"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.
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.