Scriptrunner: get cascading list values then hide and require based on selection

SKAdmin September 21, 2022
ScriptRunner Behavior  
Installed version 6.58.0 using Jira DC
I've tried every combo I can think of to get this to work based on the parent and child selection in a cascading field, but it only checks the parent, not the child. 
//If Requested By DevTeam = Art/Exterior Art then don't hide and make required

def cascadecustomField = getFieldByName("Requested By DevTeam")
def selectedOptions = cascadecustomField.getValue() as Map
def ParentOption = selectedOptions.get(0).toString()
def ChildOption = selectedOptions.get(0).toString()

// field we want hidden unless ARt/Exterior Art is selected
def hiddenField = getFieldByName("Zone")

if(ParentOption == "Art" && ChildOption == "Exterior Art"){
hiddenField.setHidden(false)
hiddenField.setRequired(true)
}
else
hiddenField.setHidden(true)
hiddenField.setRequired(false)

1 answer

1 accepted

1 vote
Answer accepted
Ram Kumar Aravindakshan _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.
September 22, 2022

Hi @SKAdmin

After going through your description, I suspect you are encountering the Bug SRJIRA-6113, where the Child value of the Cascading Select List cannot be obtained.

A fix for this Bug has already been added but is currently awaiting release, possibly in the next ScriptRunner version.

Another point to note, in your code, you seem to be using the approach below to initialise the Cascading Select List field.

def cascadecustomField = getFieldByName("Requested By DevTeam")

If you require the Behaviour to trigger based on the if/else condition that you have added, it would be best to use a Server-Side Behaviour, and you should initialise the cascading field like:-

def cascadecustomField = getFieldById(fieldChanged)

This ensures that the Behaviour will trigger when the change is made to the Cascading Select List field.

I hope this helps to solve your question. :)

Thank you and Kind regards,
Ram

SKAdmin September 22, 2022

Thank you so much for letting me know about this bug. Looking forward to seeing that fix in an upcoming release. 

Suggest an answer

Log in or Sign up to answer