List collector

imran sk
Tera Contributor

Hello,

 

We have a list collector variable, 

Variable: select user assets

If the user selects multiple values like"samsung, iPhone, ipad, macos" in which if it contains the value "IPad", I need to clear only that "ipad" value while the other values should be remaining there itself. It should only clear ipad value from the list collector variable 

 

 

How can I clear only that particular value using client script? 

 

Thanks in advance 😃 

1 REPLY 1

Community Alums
Not applicable

Hi @imran sk ,

Here is the exact required sample script as per you requirement, just make some changes as per your requirement, you are good then 😉

function onChange(control, oldValue, newValue, isLoading) {
    //Limit the number of selected options in a list collector
    //Specify the max options and variable name below
    var maxOptions = 5;
    var collectorName = 'users';
    var myListCollector = g_list.get(collectorName);
    var selectedOptions = g_form.getValue(collectorName).split(',');
    if(selectedOptions.length > maxOptions){
        //Remove the last item
        myListCollector.removeItem(selectedOptions[selectedOptions.length-1]);
        g_form.addErrorMessage('You cannot select more than ' + maxOptions + ' options.');
    }
}

 

Instead of "removeOptions" you need to use removeItem method to remove items from the list collector variable.

 

Reference: https://servicenowguru.com/scripting/client-scripts-scripting/limiting-selections-list-collector/