<?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 Re: How to get search results from SplunkJS on click of a button? in Dashboards &amp; Visualizations</title>
    <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-get-search-results-from-SplunkJS-on-click-of-a-button/m-p/206155#M12946</link>
    <description>&lt;P&gt;I've solved my own problem. The main issue is that I just did not embrace the use of Javascript callbacks. This is just wrong:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;var myResults = mySearch.data("results", {count:0});
var myrd = myResults.data();
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;myResults didn't have the data yet. It runs in the background. The idea being that it may take a while to get the data so don't block the code from running. So I had to set up a callback on the results once the data is loaded:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;var myResults = mySearch.data("results", {count:0});
myResults.on( "data", function() {
    var rows = myResults.data().rows;
    // AND SO ON
} );
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I would up embedding quite a few callbacks in there, so I have to go in and de-nest all my blocks as predefined functions to make it easier to read.&lt;/P&gt;</description>
    <pubDate>Sun, 17 Apr 2016 17:30:04 GMT</pubDate>
    <dc:creator>scottsavaresevi</dc:creator>
    <dc:date>2016-04-17T17:30:04Z</dc:date>
    <item>
      <title>How to get search results from SplunkJS on click of a button?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-get-search-results-from-SplunkJS-on-click-of-a-button/m-p/206153#M12944</link>
      <description>&lt;P&gt;I'm trying to follow the instructions here, but making the app my own a bit. I have converted my XML dashboard to HTML and am working on editing the JavaScript to make it do something. I have a button that when pressed needs to access the results of search1 (which is the manager for a TableElement) and grab the values in one of the rows. I have this so far:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;$("#closeIssue").click(function() {
            // Get the value of the key ID field
            var tokens = mvc.Components.get("default");
            var form_keyid = tokens.get("form.keyid");
            var mySearch = splunkjs.mvc.Components.getInstance("search1");
            console.log( "mysearch:", mySearch );
            var myResults = mySearch.data("results", {count:0});
            console.log( "myresults:", myResults );
            var myrd = myResults.data();
            console.log( "myrd:", myrd );
            var rows = myrd.rows;
            console.log( "rows:", rows );
            return false;
}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The problem is that the "rows" variable is undefined. Looking at the Google Chrome JavaScript console, myResults has data. Looking in the object in _data are the rows I expect to be there. However, when I call &lt;CODE&gt;myResults.data()&lt;/CODE&gt;, it returns undefined. Any thoughts on how to get the data?&lt;/P&gt;

&lt;P&gt;Thanks in advance&lt;/P&gt;</description>
      <pubDate>Fri, 15 Apr 2016 00:13:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-get-search-results-from-SplunkJS-on-click-of-a-button/m-p/206153#M12944</guid>
      <dc:creator>scottsavaresevi</dc:creator>
      <dc:date>2016-04-15T00:13:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to get search results from SplunkJS on click of a button?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-get-search-results-from-SplunkJS-on-click-of-a-button/m-p/206154#M12945</link>
      <description>&lt;P&gt;Looks like the link for the instructions I was trying to follow was not allowed in the post. The instructions I am following are the "Use KV Store with a simple app" tutorial over on dev.splunk.com. In that tutorial they have a delete button that deletes and entry in a collection using the REST API. My button is updating a row and changing one field in the row. But to do that I need to get the current value of the fields in the row out of the search so that I can use include it in the REST call.&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Sat, 16 Apr 2016 21:45:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-get-search-results-from-SplunkJS-on-click-of-a-button/m-p/206154#M12945</guid>
      <dc:creator>scottsavaresevi</dc:creator>
      <dc:date>2016-04-16T21:45:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to get search results from SplunkJS on click of a button?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-get-search-results-from-SplunkJS-on-click-of-a-button/m-p/206155#M12946</link>
      <description>&lt;P&gt;I've solved my own problem. The main issue is that I just did not embrace the use of Javascript callbacks. This is just wrong:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;var myResults = mySearch.data("results", {count:0});
var myrd = myResults.data();
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;myResults didn't have the data yet. It runs in the background. The idea being that it may take a while to get the data so don't block the code from running. So I had to set up a callback on the results once the data is loaded:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;var myResults = mySearch.data("results", {count:0});
myResults.on( "data", function() {
    var rows = myResults.data().rows;
    // AND SO ON
} );
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I would up embedding quite a few callbacks in there, so I have to go in and de-nest all my blocks as predefined functions to make it easier to read.&lt;/P&gt;</description>
      <pubDate>Sun, 17 Apr 2016 17:30:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/How-to-get-search-results-from-SplunkJS-on-click-of-a-button/m-p/206155#M12946</guid>
      <dc:creator>scottsavaresevi</dc:creator>
      <dc:date>2016-04-17T17:30:04Z</dc:date>
    </item>
  </channel>
</rss>

