Dashboards & Visualizations

How to remove searchmanager ID in mvc.js after a search in Splunk?

chrismok
Path Finder

I created a function in js and call it several times, however, once the searchmanager ID is used, the mvc.js will return an error the next time. As a result, I would like to know how can I remove the searchmanager object after search in Splunk?

function ajax(id, ids) {

    var scope1 = new SearchManager({
        "id": "scope1",
        "status_buckets": 0,
        "search": "`GetSpecDeploylog("+id+")`",
        "app": utils.getCurrentApp()
    }, {
        tokens: true,
        tokenNamespace: "submitted"
    });

    var r = scope1.data('results');
    r.on('data', function(results) {
        BuildInfo(r.data().rows[0], '#build' + ids, [ids - 1]);
        DomainRun(r.data().rows[0], '#chart' + ids, '#legend' + ids);
    });

}

yxie_splunk
Splunk Employee
Splunk Employee

This should work: splunkjs.mvc.Components.revokeInstance("scope1"). After this, you can reuse the same id.

jeffland
SplunkTrust
SplunkTrust

The solution is to create the search manager once, and then change the search of the existing search manager and start it again instead of creating a new search manager every time. It's a search manager after all, not a search.

For the example from the question, it could look like this:

var scope1 = new SearchManager({
    "id" : "scope1",
    "status_buckets" : 0,
    "search" : "`GetSpecDeploylog(" + id + ")`",
    "app" : utils.getCurrentApp()
}, {
    tokens : true,
    tokenNamespace : "submitted"
});

var r = scope1.data('results');

r.on('data', function (results) {
    BuildInfo(r.data().rows[0], '#build' + ids, [ids - 1]);
    DomainRun(r.data().rows[0], '#chart' + ids, '#legend' + ids);
});

function ajax(id, ids) {
    scope1.settings.set("search", "new search string");
    scope1.startSearch();
}

kasu_praveen
Communicator

Any solution for this problem?

0 Karma

yxie_splunk
Splunk Employee
Splunk Employee

Try this splunkjs.mvc.Components.revokeInstance("SEARCH MANAGER ID");

tom_frotscher
Builder

Hi,

I had the same problem. For a quick fix just remove the "id": "scope1" line completely. Looks like then automatically a unique id is generated with every call. I don't think this is the best method for the performance, but you can work on with your code.

Greetings

Tom

0 Karma

chrismok
Path Finder

Yes, currently I also generate the new key from "id". and for the r.on('data')...... I have to use the dirty method .....eval function to create the js script...... I hope splunk can provide the solution to us.

0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...