Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Clear Values of Multiple Choices in Dynamic Content Block on Dashboard

Dinh Nguyen
Kilo Sage

I was created a Multiple Choices by Dynamic content block as below and i was tried to create a Button for clear values, but it doesn't work ! Please someone help me ! 

DinhNguyen_0-1700627281373.png

here is the script : 

<g:evaluate>
        var table = new GlideRecord('sys_user');
        table.orderBy('name');
        table.query();
    </g:evaluate>

    <select id="multiple_choices" class="js-example-basic-single form-control interactive-filter__form-control select2 widget-content interactive-filter__widget-content" multiple="multiple">
        <j:while test="${table.next()}">
            <option value="${table.user_name}">${table.name}</option>          
        </j:while>
    </select>

    <button onclick="clearValues()">
        Clear Values
    </button>

    <script>
        $j(document).ready(function() {$j(".js-example-basic-single").select2();});  

        function clearValues() {
            document.getElementById("#multiple_choices").value = "";
        }
    </script>
1 ACCEPTED SOLUTION

Dinh Nguyen
Kilo Sage

I fixed the script as below and it's working :

function clearValues() {
            $j( ".select2-choices" ).empty();
        }

View solution in original post

1 REPLY 1

Dinh Nguyen
Kilo Sage

I fixed the script as below and it's working :

function clearValues() {
            $j( ".select2-choices" ).empty();
        }