Hi,
I have custom field "Location"(Single select Type) for which I am able to display required options in the dropdown but I am able to set a default value to the field but user is not able to modify when required . Below is the script I am using. Can someone help me fix this.
Your help is highly appreciated.
***************************************************************************************************
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_13943")
// 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 optionToSelect = options.find { it.value == "United States" }
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)
Location.setFormValue(optionToSelect.optionId)
Thanks,
Raj
Maybe no need make map?
https://scriptrunner.adaptavist.com/5.4.47/jira/behaviours-api-quickref.html#_formfield_setfieldoptions_iterable
formField.setFieldOptions(options.findAll {it.value in ['foo', 'bar']})
Hi @Raj Kumar ,
My similar example:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.customfields.manager.OptionsManager
def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cField = customFieldManager.getCustomFieldObject("customfield_id")
def cFieldValue = originalIssue.getCustomFieldValue(cField)
def optionsManager = ComponentAccessor.getComponent(OptionsManager)
def fieldConfig = cField.getRelevantConfig(issue)
def option = optionsManager.getOptions(fieldConfig).getOptionForValue("Value", null)
issue.setCustomFieldValue(cField, option)
B.R.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.