Clear List Collector Values On Change from a Lookup Select Box

Al8
Kilo Contributor

How do I clear the values of a list collector when the selection from lookup select box is changed?

find_real_file.png

Items from right bucket are not removed when value from Workstream is changed.

find_real_file.png

1 ACCEPTED SOLUTION

Allen Andreas
Administrator
Administrator

Hi,

You can create an onChange client script (https://docs.servicenow.com/bundle/orlando-application-development/page/script/client-scripts/concep...) for your workstream field, that when changed, it clears the value from your list.

g_form.clearValue('roles_field');

Replace "roles_field" with the name of your roles list field.

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

View solution in original post

6 REPLIES 6

Allen Andreas
Administrator
Administrator

Hi,

You can create an onChange client script (https://docs.servicenow.com/bundle/orlando-application-development/page/script/client-scripts/concep...) for your workstream field, that when changed, it clears the value from your list.

g_form.clearValue('roles_field');

Replace "roles_field" with the name of your roles list field.

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Hi,

I just wanted to check-in on this and see how you're doing.

If my reply above helped answer or guide you correctly, please mark it as Helpful & Correct.

Thank you!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

@Allen A : I was also working on the same requirement. What I want to do is when the selection in the SP from the list collector happens and gets added to the cart, the application name is removed. can you please help. 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var collectorName = 'cloud_application_ownership_confirmation'; //Name of the table
	
    var myListCollector = g_list.get(collectorName);

    var selectedOptions = g_form.getValue(collectorName).split(',');

    if ((selectedOptions != "") && (selectedOptions.length > 0)) {

        //Remove items

        var index = 0;

        for (var i = 1, leng = selectedOptions.length + 1; i < leng; i++) {

            myListCollector.removeItem(selectedOptions[selectedOptions.length - i]);

            index++;
            alert(" ** changed in portal ***");
        }
    }

}

Thanks! It's working now.