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

niketnilay
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

niketnilay
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

niketnilay
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!

Improve Your Security Posture

Watch NowImprove Your Security PostureCustomers are at the center of everything we do at Splunk and security ...

Maximize the Value from Microsoft Defender with Splunk

 Watch NowJoin Splunk and Sens Consulting for this Security Edition Tech TalkWho should attend:  Security ...

This Week's Community Digest - Splunk Community Happenings [6.27.22]

Get the latest news and updates from the Splunk Community here! News From Splunk Answers ✍️ Splunk Answers is ...