@genesiusj you should ideally check out Splunk Dashboard Examples app for access all the tokens in use and extend the same to clear out tokens safely.
However, let me provide your with a quick workaround for clearing all the tokens in the default and submitted token model.
PS: 1) init tokens once cleared via JS would need to be explicitly set afterwards. (2) Form tokens with default values will not reset back to default values.
So it is better to follow naming convention to ensure that you automatically unset only required tokens.
Following is a sample dashboard with all types or tokens like (1) init token, (2) drilldown token and (3) Form token.
Following is the Reset functionality implemented through SimpleXML JS extension:
Following is the SImple XML code for the example:
<form script="reset_tokens.js">
<label>Iterate through tokens</label>
<init>
<set token="tokInitTest">initialize</set>
</init>
<fieldset submitButton="false" autoRun="false">
<input type="time" token="field3" searchWhenChanged="true">
<label></label>
<default>
<earliest>-24h@h</earliest>
<latest>now</latest>
</default>
</input>
<input type="text" token="field1" searchWhenChanged="true">
<label>field1</label>
<default>test</default>
</input>
<input type="dropdown" token="field2" searchWhenChanged="true">
<label>field2</label>
<choice value="alpha">Alpha</choice>
<choice value="beta">Beta</choice>
<default>alpha</default>
</input>
</fieldset>
<row>
<panel>
<table>
<title>Click Time below to set drilldown token</title>
<search>
<done>
<set token="tokSearchTime">$result._time$</set>
</done>
<query>| makeresults</query>
<earliest>-1s</earliest>
<latest>now</latest>
</search>
<option name="refresh.display">progressbar</option>
<drilldown>
<set token="tokDrilldownSearchTime">$click.value$</set>
</drilldown>
</table>
</panel>
</row>
<row>
<panel>
<html>
<div>
tokInitTest: $tokInitTest$<br/>
tokSearchTime: $tokSearchTime$<br/>
field1: $field1$<br/>
field2: $field2$<br/>
field3.earliest: $field3.earliest$<br/>
field3.latest: $field3.latest$<br/>
tokDrilldownSearchTime: $tokDrilldownSearchTime$<br/>
</div>
<div>
<button id="reset_tokens" class="btn btn-primary">Reset</button>
</div>
</html>
</panel>
</row>
<row>
<panel>
<table>
<search>
<query>| makeresults
| eval tokInitTest=$tokInitTest|s$,
tokSearchTime=$tokSearchTime|s$,
field1=$field1|s$,
field2=$field2|s$,
field3.earliest=$field3.earliest|s$,
field3.latest=$field3.latest|s$,
tokDrilldownSearchTime=$tokDrilldownSearchTime|s$
</query>
</search>
</table>
</panel>
</row>
</form>
Following is the JS code for reset_token.js:
require(["jquery",
"splunkjs/mvc",
"splunkjs/mvc/simplexml/ready!"],
function($,mvc) {
console.log("Inside Reset button");
var defaultTokenModel=mvc.Components.get("default");
var submittedTokenModel=mvc.Components.get("submitted");
// On Click of Reset button iterate through
// default and submitted token models and unset all
$(document).on ("click","#reset_tokens",function(){
var objDefaultTokens=defaultTokenModel.attributes;
var objSubmittedTokens=submittedTokenModel.attributes;
for (var token in objDefaultTokens) {
if (objDefaultTokens.hasOwnProperty(token)) {
defaultTokenModel.unset(token);
}
}
for (var token in objSubmittedTokens) {
if (objSubmittedTokens.hasOwnProperty(token)) {
submittedTokenModel.unset(token);
}
}
});
});
... View more