Dashboards & Visualizations

How to pass a variable from a JavaScript file to search in a simple XML dashboard?

hwakonwalk
Path Finder

Hi, I have a simple XML dashboard where I use a Java Script file to display check boxes against each record and then save the checked records to a KV store on a Submit button click

Now based on the the checked boxes, I want to run a search and save another set of records to other KV store on the same button click.
To do so, I want to avoid having the second search search in Java script file and want to have in in the simple xml where I can pass the variables from JS file before button click, please help me out if there is a way to do so

Thanks,
Zubair

0 Karma

lfedak_splunk
Splunk Employee
Splunk Employee

Hey @hwakonwalk, if they answered your question, please remember to "√Accept" the answer to award karma points and to let other Splunkers know it’s a golden answer. We’re hosting a karma point contest, so it’s particularly awesome to up vote on Answers these days. 😄

0 Karma

kamlesh_vaghela
SplunkTrust
SplunkTrust

Hi

Can you please try below javascript and XML? In below example, I have set search token in javascript and used as search parameter.

my.js

require(['jquery', 'splunkjs/mvc', 'splunkjs/mvc/simplexml/ready!'], function ($,mvc) {
    var default_token_model = mvc.Components.getInstance('default');
    var submitted_tokens = mvc.Components.getInstance('submitted');
    var newQuery = "index=_internal  | stats count by sourcetype";
    default_token_model.set('searchQuery', newQuery);
    submitted_tokens.set(default_token_model.toJSON());
});

XML code

<form script="my.js">
  <label>Set Search form Javascript</label>
  <row>
    <panel>
      <table>
        <search>
          <query>$searchQuery$</query>
          <earliest>-24h@h</earliest>
          <latest>now</latest>
          <sampleRatio>1</sampleRatio>
        </search>
        <option name="count">20</option>
        <option name="dataOverlayMode">none</option>
        <option name="drilldown">none</option>
        <option name="percentagesRow">false</option>
        <option name="rowNumbers">false</option>
        <option name="totalsRow">false</option>
        <option name="wrap">true</option>
      </table>
    </panel>
  </row>
</form>
0 Karma

peterchenadded
Path Finder

See below link

http://dev.splunk.com/view/webframework-developapps/SP-CAAAEW3

Instead of mytoken use form.search

And in your simple xml you can refer to the token as $search$

0 Karma
Get Updates on the Splunk Community!

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer Certification at ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...

Share Your Ideas & Meet the Lantern team at .Conf! Plus All of This Month’s New ...

Splunk Lantern is Splunk’s customer success center that provides advice from Splunk experts on valuable data ...