Dashboards & Visualizations

How to make Splunkjs use variable in SearchManager search?

sboogaar
Path Finder

In one of our dashboard we have a table with a custom action, When the user clicks on a field we check if it is the delete field and if so get the name of the field we want to delete.

We can put it in a javascript variable.

We also have a search that needs to use this variable.

Something like: where someVariable is update in a function.

 

    
var someVariable = ""
var validateChannelCanBeDeletedSearch = new SearchManager({
 id: "validate something",
 autostart: false,
 search: `| inputlookup some
| search some_field="${someVariable}"`
});

 Later we manually trigger the search. The problem is that the update value of someVariable is not used in the query. How can we make it use the updated value.

Labels (1)
0 Karma

kamlesh_vaghela
SplunkTrust
SplunkTrust

@sboogaar 

if someVariable is a javascript variable then try this.

var someVariable = "";
var validateChannelCanBeDeletedSearch = new SearchManager({
    id: "validate something",
    autostart: false,
    search: '| inputlookup some | search some_field="'+someVariable+'"' // someVariable is javascript variable
}, { tokens: true, tokenNamespace: "submitted" });

 

if someVariable is token then try this

 

var validateChannelCanBeDeletedSearch = new SearchManager({
    id: "validate something",
    autostart: false,
    search: '| inputlookup some | search some_field="$someVariable$"' // someVariable is token
}, { tokens: true, tokenNamespace: "submitted" });

 

to trigger search execution use the below line of code.

// execute below code in any event
validateChannelCanBeDeletedSearch.startSearch();

I hope this will help you.

Thanks
KV
If any of my replies help you to solve the problem Or gain knowledge, an upvote would be appreciated.

 

0 Karma
Get Updates on the Splunk Community!

.conf25 Community Recap

Hello Splunkers, And just like that, .conf25 is in the books! What an incredible few days — full of learning, ...

Splunk App Developers | .conf25 Recap & What’s Next

If you stopped by the Builder Bar at .conf25 this year, thank you! The retro tech beer garden vibes were ...

Congratulations to the 2025-2026 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...