Forums

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

Need only selected values if some value for a custom field is selected

Aswathi D
Contributor
October 10, 2022

I have 2 fields( select list single choice ) named A and B .
A and B contains so many values as well .
My request is if A field is selected with a value XM then the field B should shows only some selected values ( not all values ).
How can I acheive this ?

1 answer

1 accepted

1 vote
Answer accepted
Florian Bonniec
Community Champion
October 10, 2022

Hi @Aswathi D 

You can do it by creating a Behaviour that is part of Scriptrunner app.

https://scriptrunner.adaptavist.com/6.20.0/jira/behaviours-overview.html

 

Regards

Aswathi D
Contributor
October 11, 2022

Hi @Florian Bonniec ,

Is it possible to show an example behaviour for this case ?

Florian Bonniec
Community Champion
October 11, 2022

Hi @Aswathi D please find below an example.

import com.atlassian.jira.component.ComponentAccessor

import com.onresolve.jira.groovy.user.FieldBehaviours

import groovy.transform.BaseScript

@BaseScript FieldBehaviours fieldBehaviours

final singleSelectListName = 'Select List'

def radioButton = getFieldById(getFieldChanged())

def allowedValues

if(radioButton.getValue() == 'A'){

    allowedValues = ['1', '2']

}

if(radioButton.getValue() == 'B'){

    allowedValues = ['3']

}

if(allowedValues){

    // Getting select field options

    def selectCustomField = customFieldManager.customFieldObjects.findByName(singleSelectListName)

    def selectConfig = selectCustomField.getRelevantConfig(issueContext)

    def selectOptions = ComponentAccessor.optionsManager.getOptions(selectConfig)

    // Filter select available options

    final selectAvailableOptions = selectOptions.findAll { it.value in allowedValues }

    getFieldByName(singleSelectListName).setFieldOptions(selectAvailableOptions)

}

In this example I have a Radio Button with value A or B

A select list with value 1, 2, 3.
When A is selected I Ihave only 1, 2 available, when B I have 3.
This script is added a script server side for the radio button.
behaviour.PNG
Regards
André Stuhrmann October 18, 2023

Hello,

I have a more or less similar request.

I need to restrict the displayed values of a field. However, there is a difference. I don't have another defining field. Instead, I need to restrict the field values to "A" and "B" only on a transition screen.

Unfortunatelly I don't have scripting skills. Can someone please help with this?

Big thanks in advance!

Best regards,
André

Suggest an answer

Log in or Sign up to answer