Forums

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

How to show fisrt option of the single select custom field instead of none

Raj Kumar July 12, 2019

Hi,

I have a single select custom field from which I want to display the first option on the request form instead of none. I am using the below code to have selected options in the custom field this working . But now instead of none I want the first value to be show in the field on request form.

Please help me in fixing this . Your help is highly appreciated.

 

location.png

import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
import com.atlassian.jira.component.ComponentAccessor
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def optionsManager = ComponentAccessor.getOptionsManager()

def Location = getFieldById("customfield_14444")


// Get access to the required custom field and options managers
def customField = customFieldManager.getCustomFieldObject(Location.getFieldId())
def config = customField.getRelevantConfig(getIssueContext())
def options = optionsManager.getOptions(config)
def optionsMap = options.findAll {
it.value in ["International",
"United States"] // list of options you want to show
}.collectEntries {
[
(it.optionId.toString()): it.value
]
}
Location.setFieldOptions(optionsMap)

 

 

Thanks,
Raj

 

2 answers

1 vote
Alexey Matveev
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.
July 12, 2019

Hello,

You do not need scripting. Go to the field configuration scheme (Project settings -> fields) and make this custom field required.

Raj Kumar July 13, 2019

But for few request types I do not display all the options I only display few options. 

For example 

I have abcd as options in location field and I want to display only ab options on x request form and want a option to be displayed instead of none when I open request form and should be able to change to b while creating a request

. I want to display CD options on y request form and want c option to be displayed instead of none when I open request form and should be able to change to d while creating a request

 

Thanks, 

Raj

Alexey Matveev
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.
July 13, 2019

I gave you an option on how you can get rid of the None option. All other things you can solve with behaviours. I thought your question was about the None option. 

Raj Kumar July 13, 2019

I have it in many screens I do not want it required in other screens making it required will be a problem. 

Without making it required do we have way to solve it using behaviours please advise. 

Thanks, 

Raj

0 votes
Raj Kumar July 13, 2019

I have this field in many screens if it is made required then it would be a problem. Without making it required can we do it using behaviours please suggest. 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events