Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to Perform a Function If Both Options of Checkbox is Selected

Özge K_ November 11, 2021

Hello,

I'm trying to manage feedback information by adding a custom field named as "External/Internal Feedback" checkbox with "External" and "Internal" options. 

If "External" is selected than "External Feedback Responsible" text field will be displayed on the screen. Else if "Internal" is selected than "Internal Feedback Responsible" user picker will be displayed on the screen. 

Until now, everything goes fine thanks to my script that written on Behaviors page as you can see below.

However, if I want to select both options nothing disappears because I guess getFieldById(getFieldChanged()) method pulls the last chenged option. It does not keep both of them.

How can I perform this function? I want to see both "Internal Feedback Responsible" and "External Feedback Responsible" if both options are selected.

1.JPG2.JPG3.JPG4.JPG5.JPG

Thanks a lot.

1 answer

1 accepted

0 votes
Answer accepted
Martin Bayer _MoroSystems_ s_r_o__
Community Champion
November 11, 2021

Hi @Özge K_ , I think the value returned from the field of checkbox type is String (when one value is seleted) or ArrayList (when multiple values are selected). You can check https://library.adaptavist.com/entity/control-form-field-based-on-selected-checkbox-value.

You need to adjust your script to work with the variables correctly. Focus on following part in the snippet

def checkBoxField = getFieldById(fieldChanged)
def checkBoxFieldValue = checkBoxField.value

def chosenValuesList = []
if (checkBoxFieldValue in String) {
chosenValuesList.add(checkBoxFieldValue)
} else if (checkBoxFieldValue in ArrayList) {
chosenValuesList.addAll(checkBoxFieldValue)
}
Özge K_ November 12, 2021

Thanks a lot Martin. It works well after some arrangements.

Martin Bayer _MoroSystems_ s_r_o__
Community Champion
November 12, 2021

Happy to help:)

Suggest an answer

Log in or Sign up to answer