List collector

Jen11
Tera Expert

I have the following list collector.  My requirement is if 'None' is selected, then the other options can not be selected, how can i achieve that? 

 

Jen11_0-1747157881387.png

 

4 REPLIES 4

Omender Singh
Tera Guru

OmenderSingh_0-1747161283760.png

 
 
function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading) return;

    // Get selected values as array
    var selectedValues = g_form.getValue('software_choices').split(',');

    var noneValue = '47708cfcc32d6e1017d6fb377d0131a4'; // sys_id of None

    // Check if 'None' is selected
    var isNoneSelected = selectedValues.includes(noneValue);

    // If 'None' is selected along with other values
    if (isNoneSelected && selectedValues.length > 1) {
        alert("You cannot select 'None' with other options. Only 'None' will be kept.");
       
        // Keep only 'None' selected
        g_form.setValue('software_choices', '');
    }
}

thank you, but that didn't work

I tried it in my PDI and it was working. 

 

Basically, you have to create a onChange client script for that variable and replace the variable value in script from "software_choices" to your variable name.

 

Also , relace the sysID of None from your instance. You can find the sysID of None by "inspect" option .

 

let me know if you have any other issue.

Ankur Bawiskar
Tera Patron
Tera Patron

@Jen11 

list collector is referring to which table?

Is "None" a value in that table being referred

why not validate this using onSubmit catalog client script?

Simply check if the value contains None and any 1 other value then throw an error and stop user from submission?

function onSubmit() {

    var selectedValuesArray = g_form.getValue('variableName').split(',');

    var noneSysId = 'sysId'; // sys_id of None record

    if (selectedValuesArray.indexOf(noneSysId) > -1 && selectedValuesArray.length > 1) {
        g_form.addErrorMessage('You cannot select other options along with none.');
        return false;
    }
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader