Show/Hide custom Text Field based on option selected in select field "drop down selection"

Michel saliba December 9, 2023

Hi All,

 

i have jira app (data center) Jira Data Center 9.12 and Scriptrunner 8.17.0 installed.

 

A cutom text field "Other" is created
A select list(single choice) "Impacted Technology" which have many option inside it "IOS,Hybrid,Android,Other"

The purpose is that when the option Other is selected from the list from the issue already created before, the text field other will be shown under the select list and should be mandatory


I have created a behaviour in Scriptrunner mapping to all projects, the affected field is "Impacted Technology" and the script inside the behaviour is the below 

// Get the value of the custom select list
def selectListField = getFieldById('Impacted Technology'); 
def selectedOption = selectListField.getValue();


// Get the text field
def textField = getFieldById('Other')

// Set the text field properties based on the selected option
if (selectedOption == "Other") {
    textField.setHidden(false);
    textField.setRequired(true);
} else {
    textField.setHidden(true);
    textField.setRequired(false);
}

But when I am creating a new issue and select Other option in the drop down list , Text field is not apperaing .
Please adivse 

3 answers

1 accepted

0 votes
Answer accepted
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 9, 2023

Either of your scripts should work.

When you disable the behaviour, do you see the text field? If not, then maybe you forgot to add it to the screen in the first place (or it's not included in your project's field config or in the custom field context).

You can further simplify the script with this:

// Get the value of the custom select list
def selectListField = getFieldByName('Impacted Technology')
def selectedOption = selectListField.getValue()

// Get the text field
def textField = getFieldByName('Other')

// Set the text field properties based on the selected option
def showField =  selectedOption == "Other"
textField.setHidden(!showField).setRequired(showField)

 

You can also add something like this to check whether the selectList field change was detected

selectListField.setHelpText("Debug: field was changed to $selectedOption")

If you don't see anything on your form, there is something wrong with your behaviour configuration.

Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 9, 2023

Oh wait, I see your mistake...

You have to use "getFieldByName" if you want to specify the field name.

Otherwise, getFieldById expects a field id like "customfield_xxxxx"

Michel saliba December 9, 2023

Hello Peter,

Thanks for your assistance.It works now.

I have used you code above.

Appreciate that.

 

Regards,
Michel

0 votes
Michel saliba December 9, 2023

Hello,

Can you please assist for the above issue ?

Regards.

0 votes
Michel saliba December 9, 2023

I Also tried the below script but also did not work

def textField = getFieldByName("Other")
def selectList = getFieldByName("Impacted Technology")

def selectListValue = selectList.getValue()

if (selectListValue == "Other") {
textField.setHidden(true)
} else {
textField.setHidden(false)
}

Please advise if also another step should be performed on jira App

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events