Dashboards & Visualizations

Splunk button javascript unset token- Is there a method to unset the splunk's token after the page refresh?

maurobissante
Explorer

Hi,

I have a button that take values from splunk's tokens, launch a search that update a KV Store and refresh the page.

Is there a method to unset the splunk's token after the page refresh?

I tried with the "tokens.unset("name of the token", null);" command in javascript but this method didn't work for me.

I took all the tokens with this command "var tokens = mvc.Components.get("default");"

Thanks,

Mauro

Labels (2)

niketn
Legend

How are you currently updating your KV Store or refreshing the page through JS? One of those can have the code to unset the token.

Also unset token code is something like the following:

tokens.unset("yourTokenName");

Besides depending on your use case you may want to unset both default and submitted token model. Further, you would need to ensure that unsetting the token does not trigger unwanted execution of token change event which you may already have.

 

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

highsplunker
Contributor

ok for me.

i just put this line into my js:

mvc.Components.get("default").unset("myToken");

thanks a lot.

0 Karma

highsplunker
Contributor

hey guys, the depends thing on dashboards worked for me only when i did this trick. i'm not sure why.

mvc.Components.get("default").unset("myToken");
mvc.Components.get("submitted").unset("myToken");

 

0 Karma

maurobissante
Explorer

In JS with the button I submit a search that update the KVStore and refresh the page.

The token came from an input fields where I set the new values of the KVStore.

After the refresh I try to unset the token.

The problem is that, after the refresh, the input fields remain full of the value of the token, instead of blank inputs.

I tried to use your command before the window.location.reload(); but it didn't work and the input form remained with the old values.

Thanks,

Mauro

0 Karma

tmurata_splunk
Splunk Employee
Splunk Employee

Try the code below to change the selection of your input.

        function unsetToken(name) {
            defaultTokenModelun.unset(name);
            submittedTokenModelun.unset(name);
        }
        unsetToken("form.TEXT_FIELD")
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!

Build the Future of Agentic AI: Join the Splunk Agentic Ops Hackathon

AI is changing how teams investigate incidents, detect threats, automate workflows, and build intelligent ...

[Puzzles] Solve, Learn, Repeat: Character substitutions with Regular Expressions

This challenge was first posted on Slack #puzzles channelFor BORE at .conf23, we had a puzzle question which ...

Splunk Community Badges!

  Hey everyone! Ready to earn some serious bragging rights in the community? Along with our existing badges ...