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