Dashboards & Visualizations

Multiselection remove ALL option when others value is picked not working on the both multi-select

DataOrg
Builder

I have two multiselect option in dashboard, with same functionality, when "ALL" options is selected other values will be reset . only either one of the dropdown is working and other is not working when unset token is used

XML code:

<input type="multiselect" token="NAME" id="ALL_RESET" searchWhenChanged="false">
         <label>Select Site</label>
         <fieldForLabel>Name</fieldForLabel>
         <fieldForValue>Name</fieldForValue>
         <search>
           <query>| inputlookup </query>
         </search>
         <change>
           <unset token="form.Brand"></unset>
         </change>
         <choice value="*">---All Brand---</choice>
         <valuePrefix>"</valuePrefix>
         <valueSuffix>"</valueSuffix>
         <delimiter>,</delimiter>
       </input>

<input type="multiselect" token="Brand" id="SERVER_RESET"  searchWhenChanged="false">
         <label>Select Server(s)</label>
         <search id="SERVER_RESET">
           <query>| inputlookup </query>
         </search>
         <fieldForLabel>BRANDNAME</fieldForLabel>
         <fieldForValue>BRANDNAME</fieldForValue>
         <delimiter>,</delimiter>
         <choice value="*">---All BRANDNAME---</choice>

       </input>

JAvascript:

var selection = [];
var multi = splunkjs.mvc.Components.getInstance("ALL_RESET");

  multi.on("change", function(){
      // get the current selection
      selection = multi.val();
      // check if there is more than one entry and one of them is "*"
      if (selection.length > 1 && ~(selection.indexOf("*"))) {
          if (selection.indexOf("*") == 0) {
              // "*" was first, remove it and leave rest
              selection.splice(selection.indexOf("*"), 1);
              multi.val(selection);
              multi.render();
          } else {
              // "*" was added later, remove rest and leave "*"
              multi.val("*");
              multi.render();
          }
      }
  });

var selection = [];
  var multi = splunkjs.mvc.Components.getInstance("SERVER_RESET"); 

  multi.on("change", function(value){
      // get the current selection
      selection = multi.val();
      // check if there is more than one entry and one of them is "*"
      if (selection.length > 1 && ~(selection.indexOf("*"))) {
          if (selection.indexOf("*") == 0) {
              // "*" was first, remove it and leave rest
              selection.splice(selection.indexOf("*"), 1);
              multi.val(selection);
              multi.render();
          } else {
              // "*" was added later, remove rest and leave "*"
              multi.val("*");
              multi.render();
          }
      }
  });
0 Karma
1 Solution

niketn
Legend

@premranjithj correct approach would be to name the multi select object in JS separately as mvc.Components.get() is invoked only once hence only the second multi select in your code would work.

Ideally, you should create an array of multiselect IDs like ALL_RESET, SERVER_RESET and loop through IDs to identify on change event handler for each. However, I will let you figure that out first. Meanwhile try the following code and confirm.

   var multiAll = splunkjs.mvc.Components.getInstance("ALL_RESET");

   multiAll.on("change", function(){
        var selection = [];
       // get the current selection
       selection = multiAll.val();
       // check if there is more than one entry and one of them is "*"
       if (selection.length > 1 && ~(selection.indexOf("*"))) {
           if (selection.indexOf("*") == 0) {
               // "*" was first, remove it and leave rest
               selection.splice(selection.indexOf("*"), 1);
               multiAll.val(selection);
               multiAll.render();
           } else {
               // "*" was added later, remove rest and leave "*"
               multiAll.val("*");
               multiAll.render();
           }
       }
   });

   var multiServer = splunkjs.mvc.Components.getInstance("SERVER_RESET"); 

   multiServer.on("change", function(){
        var selection = [];
       // get the current selection
       selection = multiServer.val();
       // check if there is more than one entry and one of them is "*"
       if (selection.length > 1 && ~(selection.indexOf("*"))) {
           if (selection.indexOf("*") == 0) {
               // "*" was first, remove it and leave rest
               selection.splice(selection.indexOf("*"), 1);
               multiServer.val(selection);
               multiServer.render();
           } else {
               // "*" was added later, remove rest and leave "*"
               multiServer.val("*");
               multiServer.render();
           }
       }
   });
____________________________________________
| makeresults | eval message= "Happy Splunking!!!"

View solution in original post

0 Karma

niketn
Legend

@premranjithj correct approach would be to name the multi select object in JS separately as mvc.Components.get() is invoked only once hence only the second multi select in your code would work.

Ideally, you should create an array of multiselect IDs like ALL_RESET, SERVER_RESET and loop through IDs to identify on change event handler for each. However, I will let you figure that out first. Meanwhile try the following code and confirm.

   var multiAll = splunkjs.mvc.Components.getInstance("ALL_RESET");

   multiAll.on("change", function(){
        var selection = [];
       // get the current selection
       selection = multiAll.val();
       // check if there is more than one entry and one of them is "*"
       if (selection.length > 1 && ~(selection.indexOf("*"))) {
           if (selection.indexOf("*") == 0) {
               // "*" was first, remove it and leave rest
               selection.splice(selection.indexOf("*"), 1);
               multiAll.val(selection);
               multiAll.render();
           } else {
               // "*" was added later, remove rest and leave "*"
               multiAll.val("*");
               multiAll.render();
           }
       }
   });

   var multiServer = splunkjs.mvc.Components.getInstance("SERVER_RESET"); 

   multiServer.on("change", function(){
        var selection = [];
       // get the current selection
       selection = multiServer.val();
       // check if there is more than one entry and one of them is "*"
       if (selection.length > 1 && ~(selection.indexOf("*"))) {
           if (selection.indexOf("*") == 0) {
               // "*" was first, remove it and leave rest
               selection.splice(selection.indexOf("*"), 1);
               multiServer.val(selection);
               multiServer.render();
           } else {
               // "*" was added later, remove rest and leave "*"
               multiServer.val("*");
               multiServer.render();
           }
       }
   });
____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Index This | What travels the world but is also stuck in place?

April 2026 Edition  Hayyy Splunk Education Enthusiasts and the Eternally Curious!   We’re back with this ...

Discover New Use Cases: Unlock Greater Value from Your Existing Splunk Data

Realizing the full potential of your Splunk investment requires more than just understanding current usage; it ...

Continue Your Journey: Join Session 2 of the Data Management and Federation Bootcamp ...

As data volumes continue to grow and environments become more distributed, managing and optimizing data ...