Set multiple-choice variable default value if more than one records show up in list collector field

Not applicable

I have a catalog item where I want to set the default value of a multiple-choice field based on the data that shows up on another list collector (this data varies based on another reference field) field.

My multiple-choice field has 3 options (Option 1, Option 2, and Option 3).

If the list collector field displays one record in the drop-down, I want Option 1 to be selected by default for the multiple-choice field.

If the list collector field displays more than one record in the drop-down, I want Option 3 to be selected by default for the multiple-choice field.

 

Please let me know if anyone can think of a way to implement this.

 

Thanks

12 REPLIES 12

Manmohan K
Tera Sage

Hi @Community Alums 

 

You can add below logic in a on change script on list collector field  (make changes to add backend names and values of the fields)

 selVals = g_form.getValue('list_collector_field');   // Replace 'list_collector_field' with the actual variable name of your list collector field

  len = selVals.split(',').length;

  if (len === 1) {
    // If only one record is selected in the list collector field
    g_form.setValue('multiple_choice_field', 'Option 1'); // Replace 'Option 1' with the desired value for Option 1 in your multiple-choice field


  } else if (len >1) { 
    // If more than one record is selected in the list collector field
    g_form.setValue('multiple_choice_field', 'Option 3'); // Replace 'Option 3' with the desired value for Option 3 in your multiple-choice field
  }

 

Not applicable

Hi @Manmohan K Thanks for the response.

 

I tried it but it did not work.

I tried all the below for my multiple-choice field along with the catalog client script

1. 'Do not select the first choice' checkbox to true on the multiple choice field

2. Tried adding a default value

3. Both 1 & 2

4. 'Do not select the first choice' checkbox to false and removed default value

All of these made no difference

Thanks

@Community Alums 

 

I have tested my script on PDI and it works

You must be doing something wrong while replacing the variable names and values of multiple choice field

Not applicable

Hi @Manmohan K & @Riya Verma I appreciate your help.

 

I re-verified again, my variables names seem fine.

 

My list collector field (site) is a reference to the 'cmn_location' table which is dependent on another field 'Company'. Depending on the 'Company' selected the drop-down values in the list collector('Site') field changes.

My multiple-choice fields actual choice list values are '1', '2' and '3'.

 

I even tried changing the script to run on change of 'Company' as well, but didn't work.

Thanks