Dashboards & Visualizations

How to disable search run in js on page load?

Path Finder

Hi,

I created a html-dashboard in which the user can choose a work station and then can click buttons for several machine faults.
If a button is pressed, a search is started in js to write the fault, the time and if the fault is coming or going to a summary index.

This is the js code from one button:

 mysearch1_K = new SearchManager({
            id: "button1_K",
            autostart: "false",
            search: mvc.tokenSafe('| makeresults | eval Störung="Störung1" | eval action="kommend" | eval Arbeitsplatz=tostring("$form.Arbeitsplatz$") | table _time Störung action Arbeitsplatz | addinfo | collect index=summary' )
        });
        $(".button1_K").on("click", function (){

            console.log(tokens.get("form.Arbeitsplatz"));


            //alert('Ausgeführt Störung 1 kommend');
            console.log("Störung1 kommend");


            //console.log(mysearch1_K.get("search"));
            mysearch1_K.startSearch();


            $(this).prop("disabled", true);

            $(".button1_G").prop("disabled", false);

        });

This is the html "code":

<div id="row1" class="dashboard-row dashboard-row1">
        <div id="panel2" class="dashboard-cell" style="width: 50%;">
            <div class="dashboard-panel clearfix">

                <div class="panel-element-row">
                    <div id="element2" class="dashboard-element html" style="width: 100%">
                        <div class="panel-body html">
                                <div>
                                    <button class="btn btn-primary button1_K btnKommend btnST">St&#246;rung 1 kommend</button>
                                    <p>Beschreibung Störung</p>
                                </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

You see that i have set the searchmanager property "autostart = false" in the code. But it runs every search (for 14 buttons like the code above) when loading the page.
Did I miss something?

Thanks!

0 Karma
1 Solution

Path Finder

Found the solution or cause by myself.

When declaring the Searchmanager with the search string:

mysearch1_K = new SearchManager({
             id: "button1_K",
             autostart: "false",
             search: mvc.tokenSafe('| makeresults | eval Störung="Störung1" | eval action="kommend" | eval Arbeitsplatz=tostring("$form.Arbeitsplatz$") | table _time Störung action Arbeitsplatz | addinfo | collect index=summary' )

the search is executed even with 'autostart: "false"'.
If I don't specify the search string in the declaration, the search is not executed:

mysearch1_K = new SearchManager({
             id: "button1_K",
             autostart: "false"

View solution in original post

0 Karma

Path Finder

Found the solution or cause by myself.

When declaring the Searchmanager with the search string:

mysearch1_K = new SearchManager({
             id: "button1_K",
             autostart: "false",
             search: mvc.tokenSafe('| makeresults | eval Störung="Störung1" | eval action="kommend" | eval Arbeitsplatz=tostring("$form.Arbeitsplatz$") | table _time Störung action Arbeitsplatz | addinfo | collect index=summary' )

the search is executed even with 'autostart: "false"'.
If I don't specify the search string in the declaration, the search is not executed:

mysearch1_K = new SearchManager({
             id: "button1_K",
             autostart: "false"

View solution in original post

0 Karma

Explorer

Hi Haph,

I'm facing the same issue. can you tell me if we can not include search in searchManager then where else we can include it.

0 Karma

Path Finder

Hi rishavvaidya,

you first declare the searchmanager like in my answer above.
Then, when you want to execute the search you first set the search string and then start the search:

 // Setting search string
searchST.settings.set("search", mvc.tokenSafe('| makeresults 1| eval Störung="'+ St +'" | eval action="kommend" | eval temp=split(tostring("$form.Arbeitsplatz$"),"_") | eval Arbeitsplatz=mvindex(temp,0) | eval Linie=mvindex(temp,1) | fields - temp | table _time Störung action Arbeitsplatz Linie | collect index=summary' ));  

// Starting search
searchST.startSearch();

And if it is important that the search exactly executed once (in my use case because the search writes a button press into the index and I want to count the presses and multiply search executions results in multiple indexed button presses instead of one) then you have to add the following after the xxx.startSearch();:

searchST.finalize();
0 Karma
State of Splunk Careers

Access the Splunk Careers Report to see real data that shows how Splunk mastery increases your value and job satisfaction.

Find out what your skills are worth!