Script Runner Behavior issue for Cascade select field condition

Being a newbie, ScriptRunner looks challenging in terms of writing code for validating Cascade select field using Behaviors module. All I’m trying is just to hide or show a text field on the fly in the “Create Screen” based on two conditional validations. Also I have already tried searching other posts but to no luck in finding a code that helps out with my specific need. I have tried the below code which works after saving the Create ticket screen only.

Any help with this code tweak would be greatly helpful, as I have bunch of similar requirements around. Thank You!!

def cascField = getFieldByName(“Please select a category”) //Cascade field

def hiddenField = getFieldByName(“Text field”) //text field
def value = cascField.getValue() as List
def cfSelect = getFieldByName(“Single select field”) //Single select field
def selectedOption = cfSelect.getValue() as String

if (value.size() == 2 && value.get(1) == “A” && selectedOption == “OptionA”) {
hiddenField.setHidden(true)
}
else
hiddenField.setHidden(false)

Any Groovy expert or ScriptRunner expert that can help me out with this code please?

We use Dynamic forms Cascade select custom field and Behaviors are not currently compatible with Dynamic Forms. Product support adaptavist confirmed having an existing improvement ticket here: SRJIRA-3401.