Record producer list collector field value selection logic for selecting None of the above option

manasa0590
Tera Contributor

We have a list collector field on record producer. we have created four values in the question_choice table and added the reference qualifier to the list collector field.

 

requirement: if the user selects one value and then if he tries to select 'none of the above' value along with the other value selected,it should throw field error message.

 

i.e User should select either a/the valid option(s) or only 'None of the above' option for the list collector field. Both values cannot be selected at the same time.

 

list collector field name: Could the AI system be used to do any of the following without substantial modification? (check all that apply)

values: 

manasa0590_0-1669626286912.png

what logic to implement in the onchange catlog client script?

1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

You can do this with an onChange Catalog Client Script when this variable changes.  List Collectors store the value as a comma-separated list of sys_ids for records on the referenced table, so your script would look like this:

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }

    if (newValue.indexOf('c938b7111b121100763d91eebc0713f0') > -1 { //None of the above selected
        var arr = newValue.split(',');
        if (arr.length > 1) {        		
            g_form.addErrorMessage('Other options cannot be selected when selecting None of the Above.');
	} else {
            g_form.clearMessages();
        }
    } else {
        g_form.clearMessages();
    }    
}

View solution in original post

4 REPLIES 4

Brad Bowman
Kilo Patron
Kilo Patron

You can do this with an onChange Catalog Client Script when this variable changes.  List Collectors store the value as a comma-separated list of sys_ids for records on the referenced table, so your script would look like this:

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }

    if (newValue.indexOf('c938b7111b121100763d91eebc0713f0') > -1 { //None of the above selected
        var arr = newValue.split(',');
        if (arr.length > 1) {        		
            g_form.addErrorMessage('Other options cannot be selected when selecting None of the Above.');
	} else {
            g_form.clearMessages();
        }
    } else {
        g_form.clearMessages();
    }    
}

Hey Brad, thanks for the quick response. 🤗

Hi Brad,

 

Now after displaying the field error message, I need to remove the recent value selected. I have used the arr.pop() method . 

manasa0590_0-1669713550616.png

But now, the error error message shows up only for a flash of time and it disappears. I want the error message to stay after the recent value is removed also.so that user can read the message and input correct values.

 

The error message stays if arr.pop() not used.

manasa0590_1-1669713838162.pngmanasa0590_2-1669713896979.png

i need to remove the last selected value and still keep the error message on, so it is visible to user.

kindly help. 

That's tricky with an onChange script since the arr.pop() is causing another change.  So you can either get rid of the two else blocks so that the message remains, but then it will be there until the form is submitted.  The other easy option is to not remove the last selected value, then have a similar onSubmit script so that the form cannot be submitted when this condition exists.