Hey Everyone,
After multiple tries in a day, I had no choice but to open this request. Hope someone would be helping me out and thanks in advance.
My use case is like, I have two single select fields(assume field A and field B) where I need to display only some values from field B based on the options selecting from the field A.
For example, field values in field A are "x", "Y" and "Z" and field B values are "1", "2" and "3". So, when i select "x" from A then "1" and "2" should be displayed and "3" should be hidden.
I've followed the scriptrunner code provided here https://community.atlassian.com/t5/Marketplace-Apps-Integrations/how-to-restrict-field-values-based-on-another-field-values/qaq-p/1094323, but still all the options are being displayed on the issue create screen.
My script is as follows: -
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
int instanceId = 11626
def instance = getFieldById("customfield_11626" + instanceId)
def instanceValue = instance.getValue()
int numberId = 10897
def number = getFieldById("customfield_10897" + numberId)
def optionsManager = ComponentAccessor.getOptionsManager()
def numberCustomField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(numberId)
def numberConfig = numberCustomField.getRelevantConfig(getIssueContext())
def options = optionsManager.getOptions(numberConfig)
if (instanceValue == "X"){
def map = ["1","2"]
def optionsMap = options.findAll {
it.value in map // list of options you want to show
}.collectEntries {
[
(it.optionId.toString()) : it.value
]
}
number.setFieldOptions(optionsMap)
}
else {
number.setFieldOptions(options)
}
Any help to get me out of this would be highly appreciated.
Thank you all.
Hi YTZ
Where are you configured the behavior code?
If you want to restrict the options based on another field, i think that you must write this code in behavior of customfield A!
Follow this steps-> https://library.adaptavist.com/entity/basics-behaviours-set-multi-select-options-value
Hope this help!
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.