Hide/ Show Dropdown Values conditionally using Script Behaviours in JIRA Cloud

Ganesh Kumar Vary November 27, 2023

Hi All,

I am trying to use Script Behaviours to hide field values of a single select custom field in JIRA Cloud depending of values of other custom field.

_________________________________________________________________________________________

I am using the below Script:

const field1 = getFieldById("customfield_xxxx")
const field2 = getFieldById("customfield_xxxy")

if (field2.getValue().value == 'Commercial')
{
field1.setOptionsVisibility(["1","2", "3", "4"], true);
}
else
{
field1.setOptionsVisibility(["5","6"], true);
}

_________________________________________________________________________________________

There are no errors in the script but somehow not working as expected. May I know any thing that I am doing wrong.

3 answers

0 votes
Nicolás Figueroa
Contributor
January 8, 2024

Hello your code is perfet, the only change is in the array select list values.

- You need to put the values IDs, which is in the Edit value in the custom field context configuration.

 

const field1 = getFieldById("customfield_xxxx")
const field2 = getFieldById("customfield_xxxy")

if (field2.getValue().value == 'Commercial')
{
field1.setOptionsVisibility(["valueID","valueID"], true);
}


0 votes
Kristian Walker _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 28, 2023

Hi Ganesh,

I can confirm that this code will need to run on the OnChange event and you will need to get the value of the changed field when it changes.

An example can be seen here, which shows how to set a value from a select list field to a text field.

You can use this script and change line 12 to make sure the value of the changedField is Commercail in your case and then in the If statement add your code to set the field values you want using the setOptionsVisibility() method.

I hope this helps.

Regards,

Kristian

Ganesh Kumar Vary November 28, 2023

Hi @Kristian Walker _Adaptavist_ 

Thanks for the response.
I have checked both OnLoad & OnChange event. So, ideally the Script should show it's output. Anyways I will try the Script you shared & will check if that will help.

0 votes
David Fischer
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 28, 2023

Hi @Ganesh Kumar Vary 

On which screen are you trying to apply this behavior? This is currently only supported on the Create screen AFAIK. 

Ganesh Kumar Vary November 28, 2023

HI @David Fischer 

Thanks for the quick response. But I can see that the functions setOptionVisibility() & getOptionVisibility() are available in create Screen & also in view screen [Ref: Behaviours (adaptavist.com)].

But I even can't see the behaviour working in create screen also. I have enabled all options- On Load, On Change, Create Screen, View Screen. But not sure if I am doing something wrong.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events