<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Button click to run a SPL search containing a token from dashboard in Dashboards &amp; Visualizations</title>
    <link>https://community.splunk.com/t5/Dashboards-Visualizations/Button-click-to-run-a-SPL-search-containing-a-token-from/m-p/452729#M29691</link>
    <description>&lt;P&gt;I need to build a js script that will run a splunk search when I click a button on my dashboard. &lt;/P&gt;

&lt;P&gt;The search within the .js file needs to: (1)  get a token I have set on the dashboard which is $host_tok$ and (2) append the search results to a kv store (named: collected-data) I already have setup.&lt;/P&gt;

&lt;P&gt;I would also like the js script to ask for confirmation (yes/no) "Are you sure you want to add $host_tok$ data to the collected-data kv store?" Clicking yes will run the search. Clicking no will close the notification window. &lt;/P&gt;

&lt;P&gt;I have a basic understanding of js, but I don't work with it enough to remember how I would build this script. &lt;/P&gt;

&lt;P&gt;dashboard xml:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;    &amp;lt;form script="run_action_test.js"&amp;gt;
      &amp;lt;fieldset submitButton="false"&amp;gt;
        &amp;lt;input id="host" type="dropdown" token="host_tok"&amp;gt;
          &amp;lt;label&amp;gt;Host&amp;lt;/label&amp;gt;
          &amp;lt;fieldForLabel&amp;gt;host&amp;lt;/fieldForLabel&amp;gt;
          &amp;lt;fieldForValue&amp;gt;host&amp;lt;/fieldForValue&amp;gt;
          &amp;lt;search&amp;gt;
            &amp;lt;query&amp;gt;index=main sourcetype=test | stats count by host&amp;lt;/query&amp;gt;
            &amp;lt;earliest&amp;gt;$time_tok.earliest$&amp;lt;/earliest&amp;gt;
            &amp;lt;latest&amp;gt;$time_tok.latest$&amp;lt;/latest&amp;gt;
          &amp;lt;/search&amp;gt;
          &amp;lt;prefix&amp;gt;host=&amp;lt;/prefix&amp;gt;
        &amp;lt;/input&amp;gt;
        &amp;lt;input type="time" token="time_tok"&amp;gt;
          &amp;lt;label&amp;gt;&amp;lt;/label&amp;gt;
          &amp;lt;default&amp;gt;
            &amp;lt;earliest&amp;gt;-7d@h&amp;lt;/earliest&amp;gt;
            &amp;lt;latest&amp;gt;now&amp;lt;/latest&amp;gt;
          &amp;lt;/default&amp;gt;
        &amp;lt;/input&amp;gt;
      &amp;lt;/fieldset&amp;gt;
    ...
      &amp;lt;row&amp;gt;
        &amp;lt;panel&amp;gt;
          &amp;lt;html
             &amp;lt;buttton class="btn btn-primary button1"&amp;gt;Copy to KV Store!&amp;lt;/button&amp;gt;
          &amp;lt;/html&amp;gt;
        &amp;lt;/panel&amp;gt;
      &amp;lt;/row&amp;gt;
    ...
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 16 Aug 2019 19:49:20 GMT</pubDate>
    <dc:creator>alinadejeu</dc:creator>
    <dc:date>2019-08-16T19:49:20Z</dc:date>
    <item>
      <title>Button click to run a SPL search containing a token from dashboard</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Button-click-to-run-a-SPL-search-containing-a-token-from/m-p/452729#M29691</link>
      <description>&lt;P&gt;I need to build a js script that will run a splunk search when I click a button on my dashboard. &lt;/P&gt;

&lt;P&gt;The search within the .js file needs to: (1)  get a token I have set on the dashboard which is $host_tok$ and (2) append the search results to a kv store (named: collected-data) I already have setup.&lt;/P&gt;

&lt;P&gt;I would also like the js script to ask for confirmation (yes/no) "Are you sure you want to add $host_tok$ data to the collected-data kv store?" Clicking yes will run the search. Clicking no will close the notification window. &lt;/P&gt;

&lt;P&gt;I have a basic understanding of js, but I don't work with it enough to remember how I would build this script. &lt;/P&gt;

&lt;P&gt;dashboard xml:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;    &amp;lt;form script="run_action_test.js"&amp;gt;
      &amp;lt;fieldset submitButton="false"&amp;gt;
        &amp;lt;input id="host" type="dropdown" token="host_tok"&amp;gt;
          &amp;lt;label&amp;gt;Host&amp;lt;/label&amp;gt;
          &amp;lt;fieldForLabel&amp;gt;host&amp;lt;/fieldForLabel&amp;gt;
          &amp;lt;fieldForValue&amp;gt;host&amp;lt;/fieldForValue&amp;gt;
          &amp;lt;search&amp;gt;
            &amp;lt;query&amp;gt;index=main sourcetype=test | stats count by host&amp;lt;/query&amp;gt;
            &amp;lt;earliest&amp;gt;$time_tok.earliest$&amp;lt;/earliest&amp;gt;
            &amp;lt;latest&amp;gt;$time_tok.latest$&amp;lt;/latest&amp;gt;
          &amp;lt;/search&amp;gt;
          &amp;lt;prefix&amp;gt;host=&amp;lt;/prefix&amp;gt;
        &amp;lt;/input&amp;gt;
        &amp;lt;input type="time" token="time_tok"&amp;gt;
          &amp;lt;label&amp;gt;&amp;lt;/label&amp;gt;
          &amp;lt;default&amp;gt;
            &amp;lt;earliest&amp;gt;-7d@h&amp;lt;/earliest&amp;gt;
            &amp;lt;latest&amp;gt;now&amp;lt;/latest&amp;gt;
          &amp;lt;/default&amp;gt;
        &amp;lt;/input&amp;gt;
      &amp;lt;/fieldset&amp;gt;
    ...
      &amp;lt;row&amp;gt;
        &amp;lt;panel&amp;gt;
          &amp;lt;html
             &amp;lt;buttton class="btn btn-primary button1"&amp;gt;Copy to KV Store!&amp;lt;/button&amp;gt;
          &amp;lt;/html&amp;gt;
        &amp;lt;/panel&amp;gt;
      &amp;lt;/row&amp;gt;
    ...
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 16 Aug 2019 19:49:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Button-click-to-run-a-SPL-search-containing-a-token-from/m-p/452729#M29691</guid>
      <dc:creator>alinadejeu</dc:creator>
      <dc:date>2019-08-16T19:49:20Z</dc:date>
    </item>
    <item>
      <title>Re: Button click to run a SPL search containing a token from dashboard</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Button-click-to-run-a-SPL-search-containing-a-token-from/m-p/452730#M29692</link>
      <description>&lt;P&gt;@alinadejeu refer to one of my older answers on similar lines &lt;A href="https://answers.splunk.com/answers/600664/dashboard-button-to-run-spl-on-click.html"&gt;https://answers.splunk.com/answers/600664/dashboard-button-to-run-spl-on-click.html&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;You would need to adjust as per your needs like add Ok/Cancel &lt;CODE&gt;confirm()&lt;/CODE&gt; box in the JavaScript code.&lt;/P&gt;</description>
      <pubDate>Sat, 17 Aug 2019 03:32:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Button-click-to-run-a-SPL-search-containing-a-token-from/m-p/452730#M29692</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2019-08-17T03:32:17Z</dc:date>
    </item>
    <item>
      <title>Re: Button click to run a SPL search containing a token from dashboard</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Button-click-to-run-a-SPL-search-containing-a-token-from/m-p/452731#M29693</link>
      <description>&lt;P&gt;Thank I was able to do what I needed with a simple savedsearched for now. &lt;/P&gt;</description>
      <pubDate>Tue, 20 Aug 2019 16:53:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Button-click-to-run-a-SPL-search-containing-a-token-from/m-p/452731#M29693</guid>
      <dc:creator>alinadejeu</dc:creator>
      <dc:date>2019-08-20T16:53:20Z</dc:date>
    </item>
  </channel>
</rss>

