How To Reset All Input’s Tokens With A one-click In Splunk Dashboard

How To Reset All Input’s Tokens With A one-click In Splunk Dashboard

Note: Please go through the following blog, before starting this one “Create A Comment Box In Splunk Dashboard & Which Will Store The Information In A Lookup File.
So without wasting many times let’s get to the use case, as you know from the above link that previously we created a “Comment User Interface” in the Splunk dashboard. In that dashboard, we will add an extra feature, that will add a button, which will reset all the inputs token with a single click.

This was our comment dashboard and the highlighted portions are the inputs for your entry to make a new comment.
Now suppose you made an entry (comment), and as soon you hit submit, comments will be submitted. Now if you want to put another entry back to back, then you need to remove older entries from the input box and need to put new comments, now here we will minimize the user action by adding a button to remove all the entries from the input boxes at one click.

At first,
Create a JavaScript ( resetnew.js ) file with the following code.

], function ($, mvc) {
var tokens = mvc.Components.get("default");
$('#buttonId').on("click", function (e){
tokens.set("", " ");
tokens.set("form.cmt", " ");
tokens.set("form.rts", " ");

The complete js is given below,

After this put this js on the following path.

$SPLUNK_HOME/etc/apps/<app name>/appserver/static

And restart your Splunk server.

You can also know about :  How To Find The Missing Values Of A Field By Comparing A Lookup File


Probably you have to change the underlined portions from the script if you are using tokens with some other name and the rest will remain unchanged.
Now go to the dashboard and click on Edit and select Source code.

Now within the from tag add “script=restartnew.js
And add the following HTML to create the reset button. You can remove <p>username<p>  portion if you don’t want any paragraph. We have used just for testing purpose. 

Save your dashboard and refresh it.
Now go to your dashboard.

As you can see the “Reset Older” button is been created and working fine. You can check it, put some inputs in the text box, and after hitting submit click on the “Reset Older” button, and all the inputs will be removed from the text box. I.e. all inserted values will be reset.
The complete source code is given below,

Happy Splunking !!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.