Dashboards & Visualizations

How can I make one button unset other button tokens?

DataOrg
Builder

I have 4 buttons with different tokens. If I click button1 I want to unset other buttons token. data-unset-token allows only one token unset.

   <button style="width: 300px" class="butn1" data-set-token="script_name" data-unset-token="send_mail" data-value="">File Status</button>

<button style="width: 300px" class="butn2" data-set-token="send_mail" data-unset-token="script_name" data-value="">File Status2</button>

<button style="width: 300px" class="butn3" data-set-token="Upcoming" data-unset-token="send_mail" data-value="">Upcoming Batc3h</button>

<button style="width: 300px" class="butn4" data-set-token="previous" data-unset-token="script_name" data-value="">Previous Bat4ch</button>
0 Karma
1 Solution

niketn
Legend

@DataOrg, please try the following option

Step 1) Add IDs to all your buttons for example id="but1", id="but2" etc. One example is given below:

File Status
PS: Similarly add ids for other buttons. You can use them in jQuery code.

Step 2) Create a JavaScript file (unset_button_tokens.js) to unset all tokens on button click

require({
     "splunkjs/mvc",
     "jquery",
     "splunkjs/mvc/simplexml/eventhandler"
     ],
     function(
           mvc,
           $,
           EventHandler
     ){
      //Button for script_name
      $.('#butn1').on("click",function(){
              EventHandler.unsetToken('send_mail');
              EventHandler.unsetToken('Upcoming');
              EventHandler.unsetToken('previous');
      });
      //Button for send_mail
      $.('#butn2').on("click",function(){
              EventHandler.unsetToken('script_name');
              EventHandler.unsetToken('Upcoming');
              EventHandler.unsetToken('previous');
      });
      //Button for Upcoming
      $.('#butn3').on("click",function(){
              EventHandler.unsetToken('send_mail');
              EventHandler.unsetToken('script_name');
              EventHandler.unsetToken('previous');
      });
      //Button for previous
      $.('#butn4').on("click",function(){
              EventHandler.unsetToken('send_mail');
              EventHandler.unsetToken('script_name');
              EventHandler.unsetToken('Upcoming');
      });
});

Step 3) Include unset_button_tokens.js to your dashboard. Based on your example it is HTML Dashboard. So you can add the following code between final end script tag and end body tag i.e.

    </script>
    <script src="{{SPLUNKWEB_URL_PREFIX}}/static/app/<YourAppName>/unset_button_tokens.js"></script>
    </body>
</html>

PS: You need to provide your own app name above.
Step 4) You would need to restart/refresh/bump Splunk and also clear browser history for JavaScript to pick up.

Please try out and let us know.

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"

View solution in original post

niketn
Legend

@DataOrg, please try the following option

Step 1) Add IDs to all your buttons for example id="but1", id="but2" etc. One example is given below:

File Status
PS: Similarly add ids for other buttons. You can use them in jQuery code.

Step 2) Create a JavaScript file (unset_button_tokens.js) to unset all tokens on button click

require({
     "splunkjs/mvc",
     "jquery",
     "splunkjs/mvc/simplexml/eventhandler"
     ],
     function(
           mvc,
           $,
           EventHandler
     ){
      //Button for script_name
      $.('#butn1').on("click",function(){
              EventHandler.unsetToken('send_mail');
              EventHandler.unsetToken('Upcoming');
              EventHandler.unsetToken('previous');
      });
      //Button for send_mail
      $.('#butn2').on("click",function(){
              EventHandler.unsetToken('script_name');
              EventHandler.unsetToken('Upcoming');
              EventHandler.unsetToken('previous');
      });
      //Button for Upcoming
      $.('#butn3').on("click",function(){
              EventHandler.unsetToken('send_mail');
              EventHandler.unsetToken('script_name');
              EventHandler.unsetToken('previous');
      });
      //Button for previous
      $.('#butn4').on("click",function(){
              EventHandler.unsetToken('send_mail');
              EventHandler.unsetToken('script_name');
              EventHandler.unsetToken('Upcoming');
      });
});

Step 3) Include unset_button_tokens.js to your dashboard. Based on your example it is HTML Dashboard. So you can add the following code between final end script tag and end body tag i.e.

    </script>
    <script src="{{SPLUNKWEB_URL_PREFIX}}/static/app/<YourAppName>/unset_button_tokens.js"></script>
    </body>
</html>

PS: You need to provide your own app name above.
Step 4) You would need to restart/refresh/bump Splunk and also clear browser history for JavaScript to pick up.

Please try out and let us know.

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"

DataOrg
Builder

thanks working. i am not getting up vote button

0 Karma

niketn
Legend

@premranjithj I just noticed this old answer of mine which worked for you. I have converted to answer. Please Accept to mark this as answered!

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma
Get Updates on the Splunk Community!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...