Dashboards & Visualizations

Pass token to oneshotSearch

komalg
New Member

Hi,

Inside my dashboard I am executing a oneshotSearch in my html dashboard using javascript. How do I pass tokens to this search?

service2.oneshotSearch(
  searchQuery,
  searchParams,
  function(err, results) {
    // Display the results....}

var searchQuery = "...\"$form.Application$\" ";

I tried the above syntax and it does not work. It has to be a html dashboard.

Thanks.

0 Karma

paramagurukarth
Builder

You can get the token value in you custom module and for your query..
Read this doc.. this got all you want..
You can even attach on-change events to a token object and change your query correspondingly

http://dev.splunk.com/view/SP-CAAAE25#Addingcode:usingJavaScriptandSearchProcessingLanguage-Workingw...

Also https://www.youtube.com/watch?v=lojUc9v37Jg&list=PL7zWAA-DF0k9U_s1w5EY33o2JqJgdHRGz&index=2

0 Karma

komalg
New Member

I have the token by doing the tokens.get call and the token has the value also.
I need the way to pass this token to the query in the oneshot search. I am sure there is way, could not find it right syntax for it.

Thanks.

0 Karma

paramagurukarth
Builder

instead of this,
var searchQuery = "...\"$form.Application$\" ";

try

var defaultTokens = mvc.Components.get("default"); 
var submittedTokens = mvc.Components.get("submitted"); 
var tokens = {
    get: function(tokenName) {
        return defaultTokens.get(tokenName);
    },

    set: function(tokenName, tokenValue) {
        defaultTokens.set(tokenName, tokenValue);
        submittedTokens.set(tokenName, tokenValue);
    }, 
    on: function(eventName, callback) { 
        defaultTokens.on(eventName, callback); 
    }
};
var searchQuery = "..."  + (tokens.get("Application") || tokens.get("form.Application")) + "... ";
0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

What Is Splunk? Here’s What You Can Do with Splunk

Hey Splunk Community, we know you know Splunk. You likely leverage its unparalleled ability to ingest, index, ...

Level Up Your .conf25: Splunk Arcade Comes to Boston

With .conf25 right around the corner in Boston, there’s a lot to look forward to — inspiring keynotes, ...

Manual Instrumentation with Splunk Observability Cloud: How to Instrument Frontend ...

Although it might seem daunting, as we’ve seen in this series, manual instrumentation can be straightforward ...