Hi all,
I am trying to start a search with javascript after a user clicks on an "ok" button in a pop-up.
So far, so good it is working and triggering the request.
However, I am unable to do it several times as it says "Error: Already have instance with id: mysearch"
I am not familiar at all with javascript and Splunk Search Manager functions... I tried to use:
delete mysearch;
...thinking it would delete the variable that holds the search manager instance and remove the object... but it doesn't seem to work.
Here is my code:
require([
"jquery",
"splunkjs/mvc/searchmanager",
"splunkjs/mvc",
"splunkjs/mvc/simplexml/ready!"
], function(
$,
SearchManager
) {
$("#btn-submit").on("click", function (){
var defaultTokenModel = splunkjs.mvc.Components.getInstance("default");
var totok = defaultTokenModel.get("totok");
var mysearch = new SearchManager(totok,{
id: "mysearch",
autostart: "false",
search: "|makeresults eval test="+totok+"|eval toto='true'"
});
var ok = confirm("Confirm you want to start the search!");
if ( ok==true ){
mysearch.startSearch(totok);
mysearch.finalize();
console.log("just closed it");
} else {
alert('You cancelled this action!');
}
});
});
Basically it opens a pop up whenever I click on a button and finds the token value I set in the dashboard when clicking on a row.
Not sure if that can help but I'm also giving the dashboard code:
<form script="test.js">
<label>Dashboard with Javascript on Button</label>
<fieldset submitButton="false">
<input type="text" token="field1">
<label>"$totok$"</label>
</input>
</fieldset>
<row>
<panel>
<html>
<div>
<input id="btn-submit" type="button" value="Click"/>
</div>
</html>
</panel>
</row>
<row>
<panel>
<table>
<search>
<query>|makeresults | eval test="tokenvalue"</query>
<earliest>-24h@h</earliest>
<latest>now</latest>
</search>
<option name="drilldown">cell</option>
<drilldown>
<set token="totok">$click.value2$</set>
</drilldown>
</table>
</panel>
</row>
</form>
Thank you for your help!
... View more