Dashboards & Visualizations

How to run query after javascript on initial load

verothor
Path Finder

Hi guys,

I am trying to set up a code in javascript which will refresh page after javascript run,

because now my dashboards loads, but javascript run first and the visualizations depends on javascript and then coloring for example don't change.

When I tried to put refresh under query to 5seconds, then it was reloaded and all visualizations were loaded, but I would like to do it better way and I am sure with javascript is possible, but I am very basic with javascript, so I was searching here, but nothing worked, because mainly it was set up, that after some button click the javascript will reload the page, but I would like to have it automatically.

Thank you for any ideas.

v.

 

 

Labels (2)
Tags (1)
0 Karma

kamlesh_vaghela
SplunkTrust
SplunkTrust

@verothor 

Have you tried something like this?

require([
    'underscore',
    'jquery',
    'splunkjs/mvc',
    "splunkjs/mvc/searchmanager",
    'splunkjs/mvc/simplexml/ready!'
], function (_, $, mvc, SearchManager) {

    let mySearch = new SearchManager({
        id: "mysearch",
        autostart: "false",
        search: '| makeresults | eval test = "This is test" ',
        preview: false,
    }, { tokens: true, tokenNamespace: "submitted" });

    let mySearchResults = mySearch.data("results");
    mySearchResults.on("data", function () {
        resultArray = mySearchResults.data().rows;
        console.log("My Data", resultArray);
    });

    $(document).ready(function () {
        setInterval(function () {
            mySearch.startSearch();
        }, 3000);
    });
});

 

Note: This is a sample JS. Just modify as per your requirement. 

 

KV

0 Karma
Get Updates on the Splunk Community!

Brains, Bytes, and Boston: Learn from the Best at .conf25

When you think of Boston, you might picture colonial charm, world-class universities, or even the crack of a ...

Splunk AppDynamics Agents Webinar Series

Mark your calendars! On June 24th at 12PM PST, we’re going live with the second session of our Splunk ...

SplunkTrust Application Period is Officially OPEN!

It's that time, folks! The application/nomination period for the 2025 SplunkTrust is officially open! If you ...