Forums

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

Scriptrunner Single Select List Behaviour not working on Issue create screen!!

YTZ February 13, 2023

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.

1 answer

1 vote
David A
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.
February 13, 2023

Hi YTZ

Where are you configured the behavior code?

  • Initializer?
  • A Customfield?
  • B Customfield?

 

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!

Suggest an answer

Log in or Sign up to answer