Hide a text field on Multi-Level Cascading Select change
Tested on September 10, 2024, Jira 9.12.8, ScriptRunner 8.33.0, Multi-Level Cascading Select 7.0.2.
You can add a behaviour that hides a text field according to the value of our MLCS field.
For this example, we will be using a text field, called “Single line text field” and a Multi-Level Cascading Select Field, called “Multi-Level Cascading Select”, with three levels of options.
In the ScriptRunner tab, click on Behaviours.
Create a behaviour (here called “Hide a text field on MLCS field change“) and define a mapping to select the projects and types of issues affected by the behaviour.
At the bottom of the page, add your text field by clicking on “Add Field”.
Once the field is added, click on Create Script and paste the following script:
//define the variables
//the number after ":" defines the level of the options that will be taken under consideration.In this case, only 3rd levels will be checked (starts from 0)
def mlcs = getFieldById("customfield_10112:1");// MLCS field
def mlcsVal = mlcs.getValue();
def textField = getFieldByName("field_to_hide");
//get the MLCS value logged
log.error("Department's First-Level value is " + mlcsVal);
if("10003".equals(mlcsVal)){ //10124 is a third layer option.
textField.setHidden(true);
}else{
textField.setHidden(false);
}
In this example code, the text field will be set to hidden if the third layer’s option ID is 10124, otherwise, it will be set back to visible.
Now, navigate to your issue. You will see that the text field “Employee” will be shown or hidden based on the option selected on your MLCS field: