<?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: Why does the SearchManager data event fire more than once in Splunk 6.5.2? in Splunk Dev</title>
    <link>https://community.splunk.com/t5/Splunk-Dev/Why-does-the-SearchManager-data-event-fire-more-than-once-in/m-p/312483#M4265</link>
    <description>&lt;P&gt;Hi Redman11,&lt;/P&gt;

&lt;P&gt;did you find a solution for this problem? I have exactly the same problem. &lt;BR /&gt;
Thank you in advance!&lt;/P&gt;</description>
    <pubDate>Mon, 29 May 2017 20:24:16 GMT</pubDate>
    <dc:creator>bjoukhadar</dc:creator>
    <dc:date>2017-05-29T20:24:16Z</dc:date>
    <item>
      <title>Why does the SearchManager data event fire more than once in Splunk 6.5.2?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Why-does-the-SearchManager-data-event-fire-more-than-once-in/m-p/312482#M4264</link>
      <description>&lt;P&gt;I've just upgraded to Splunk 6.5.2 from 6.3.1 and the data event of the SearchManager seems to be firing twice under certain circumstances.  This behaviour was not present in 6.3.1.  Is this a bug?  I'm aware that some of the search events have changed in 6.5 (e.g. finalized has been removed), but I can't find anything referring to this behaviour in the documentation.  Some very simple code below demonstrates the problem:&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;JavaScript&lt;/STRONG&gt; tester.js&lt;/P&gt;

&lt;P&gt;require([&lt;BR /&gt;
  'underscore',&lt;BR /&gt;
  'jquery',&lt;BR /&gt;
  'splunkjs/mvc',&lt;BR /&gt;
  'splunkjs/mvc/searchmanager',&lt;BR /&gt;
  'splunkjs/mvc/simplexml/ready!'&lt;BR /&gt;
], function(_, $, mvc, SearchManager) {&lt;/P&gt;

&lt;P&gt;var searchManager = new SearchManager({&lt;BR /&gt;
    autostart: false,&lt;BR /&gt;
    search: "| makeresults"&lt;BR /&gt;
  });&lt;/P&gt;

&lt;P&gt;searchManager.data("results").on('data', function() {&lt;BR /&gt;
    console.log("data event fired");&lt;BR /&gt;
  });&lt;/P&gt;

&lt;P&gt;searchManager.startSearch();&lt;BR /&gt;
});&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;SimpleXML&lt;/STRONG&gt; tester.xml&lt;/P&gt;

&lt;P&gt;&amp;lt;form script="tester.js"&amp;gt;&lt;BR /&gt;
&amp;lt;label&amp;gt;Tester&amp;lt;/label&amp;gt;&lt;/P&gt;

&lt;P&gt;&amp;lt;row&amp;gt;&lt;BR /&gt;
    &lt;PANEL&gt;&lt;BR /&gt;
      Test of data event&lt;BR /&gt;
    &lt;/PANEL&gt;&lt;BR /&gt;
  &amp;lt;/row&amp;gt;&lt;/P&gt;

&lt;P&gt;&amp;lt;/form&amp;gt;&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Console Output&lt;/STRONG&gt;&lt;BR /&gt;
data event fired&lt;BR /&gt;
data event fired&lt;/P&gt;

&lt;P&gt;If I use the _bump command, and then reload the tester.xml dashboard page, the data event only fires once.   If I reload the page again, it fires twice, and then continues to fire twice until I call _bump again.  Has anyone experienced this issue?&lt;/P&gt;</description>
      <pubDate>Tue, 21 Feb 2017 09:43:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Why-does-the-SearchManager-data-event-fire-more-than-once-in/m-p/312482#M4264</guid>
      <dc:creator>Redman11</dc:creator>
      <dc:date>2017-02-21T09:43:14Z</dc:date>
    </item>
    <item>
      <title>Re: Why does the SearchManager data event fire more than once in Splunk 6.5.2?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Why-does-the-SearchManager-data-event-fire-more-than-once-in/m-p/312483#M4265</link>
      <description>&lt;P&gt;Hi Redman11,&lt;/P&gt;

&lt;P&gt;did you find a solution for this problem? I have exactly the same problem. &lt;BR /&gt;
Thank you in advance!&lt;/P&gt;</description>
      <pubDate>Mon, 29 May 2017 20:24:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Why-does-the-SearchManager-data-event-fire-more-than-once-in/m-p/312483#M4265</guid>
      <dc:creator>bjoukhadar</dc:creator>
      <dc:date>2017-05-29T20:24:16Z</dc:date>
    </item>
    <item>
      <title>Re: Why does the SearchManager data event fire more than once in Splunk 6.5.2?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Why-does-the-SearchManager-data-event-fire-more-than-once-in/m-p/312484#M4266</link>
      <description>&lt;P&gt;Hi, no I don't yet have a solution that isn't a hack.  I was going to upgrade to 6.6 and see if it is resolved then.  If not, I'll raise a support case with Splunk.&lt;/P&gt;</description>
      <pubDate>Tue, 30 May 2017 08:34:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Why-does-the-SearchManager-data-event-fire-more-than-once-in/m-p/312484#M4266</guid>
      <dc:creator>Redman11</dc:creator>
      <dc:date>2017-05-30T08:34:05Z</dc:date>
    </item>
    <item>
      <title>Re: Why does the SearchManager data event fire more than once in Splunk 6.5.2?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Why-does-the-SearchManager-data-event-fire-more-than-once-in/m-p/312485#M4267</link>
      <description>&lt;P&gt;For info - this behaviour is still present in Splunk 6.6.1&lt;/P&gt;</description>
      <pubDate>Thu, 08 Jun 2017 14:06:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Why-does-the-SearchManager-data-event-fire-more-than-once-in/m-p/312485#M4267</guid>
      <dc:creator>Redman11</dc:creator>
      <dc:date>2017-06-08T14:06:52Z</dc:date>
    </item>
    <item>
      <title>Re: Why does the SearchManager data event fire more than once in Splunk 6.5.2?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Why-does-the-SearchManager-data-event-fire-more-than-once-in/m-p/312486#M4268</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;
Have you found any resolution to this issue?&lt;/P&gt;</description>
      <pubDate>Fri, 01 Dec 2017 10:32:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Why-does-the-SearchManager-data-event-fire-more-than-once-in/m-p/312486#M4268</guid>
      <dc:creator>hwakonwalk</dc:creator>
      <dc:date>2017-12-01T10:32:11Z</dc:date>
    </item>
    <item>
      <title>Re: Why does the SearchManager data event fire more than once in Splunk 6.5.2?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Why-does-the-SearchManager-data-event-fire-more-than-once-in/m-p/312487#M4269</link>
      <description>&lt;P&gt;This was raised by me to Engineering after Redman11 contacted support and was explained as expected, and the way that results are requested has changed in 6.4+:&lt;/P&gt;

&lt;HR /&gt;

&lt;P&gt;As per the given JS file the "data event fired for results" message will show up in console when we get data for the search/jobs//results? request. &lt;BR /&gt;
The UI keeps making the search/jobs?id= request and based on its response it decides whether to make the search/jobs//results? request or not. &lt;/P&gt;

&lt;P&gt;If the resultPreviewCount property in the response of search/jobs?id= request is greater than 0 only then the UI makes the search/jobs//results? request. &lt;/P&gt;

&lt;P&gt;In 6.3.x, we get resultPreviewCount: 0 for all the search/jobs?id= requests except for the last one after which we make the search/jobs//results? request. &lt;BR /&gt;
Second last search/jobs?id= responds with resultPreviewCount: 0. &lt;BR /&gt;
Last search/jobs?id= responds with resultPreviewCount: 9. &lt;/P&gt;

&lt;P&gt;In 6.4.x, we get resultPreviewCount: 10 for all the search/jobs?id= so thats why we keep making search/jobs//results? request after each of them. &lt;BR /&gt;
Second last search/jobs?id= responds with resultPreviewCount: 10 &lt;BR /&gt;
Last search/jobs?id= responds with resultPreviewCount: 10 &lt;/P&gt;

&lt;H2&gt;Since the search/jobs?id= and the search/jobs//results? requests are made one after the other, you are seeing "data event fired for results" message in the browser's console multiple times. &lt;/H2&gt;

&lt;H2&gt;My added explanation:&lt;/H2&gt;

&lt;P&gt;so if you're relying on the ondata event, you'll need to take that into account that it might fire multiple times on newer splunk versions. &lt;/P&gt;

&lt;H2&gt;The main point seems to be if resultPreviewCount is the same as the resultCount (and not zero), that's the last request&lt;/H2&gt;

&lt;P&gt;(This has been a while ago, so just copy pasting this from the case)&lt;/P&gt;</description>
      <pubDate>Mon, 04 Dec 2017 10:28:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Why-does-the-SearchManager-data-event-fire-more-than-once-in/m-p/312487#M4269</guid>
      <dc:creator>mhoogcarspel_sp</dc:creator>
      <dc:date>2017-12-04T10:28:09Z</dc:date>
    </item>
    <item>
      <title>Re: Why does the SearchManager data event fire more than once in Splunk 6.5.2?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Why-does-the-SearchManager-data-event-fire-more-than-once-in/m-p/312488#M4270</link>
      <description>&lt;P&gt;Is this still an expected behavior? I notice this issue quite frequently when dealing with a savedsearch and a postprocess vice a search. &lt;/P&gt;

&lt;P&gt;If this is still expected behavior, are there any workarounds to guaranteeing only one set of a data? I am creating divs based on the data returned and my workaround is to run a function to delete all divs when it starts otherwise I end up with 2-4 times as many sets of data.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Mar 2019 12:38:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Why-does-the-SearchManager-data-event-fire-more-than-once-in/m-p/312488#M4270</guid>
      <dc:creator>jazzypai</dc:creator>
      <dc:date>2019-03-12T12:38:34Z</dc:date>
    </item>
    <item>
      <title>Re: Why does the SearchManager data event fire more than once in Splunk 6.5.2?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Why-does-the-SearchManager-data-event-fire-more-than-once-in/m-p/312489#M4271</link>
      <description>&lt;P&gt;I have still the same issue on 7.2.6.&lt;BR /&gt;
But it occurs not with every search. Just now and then two events are stored after calling Searchmanager.startSearch()&lt;/P&gt;

&lt;P&gt;Any Solution?&lt;/P&gt;</description>
      <pubDate>Fri, 20 Sep 2019 13:04:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Why-does-the-SearchManager-data-event-fire-more-than-once-in/m-p/312489#M4271</guid>
      <dc:creator>haph</dc:creator>
      <dc:date>2019-09-20T13:04:05Z</dc:date>
    </item>
    <item>
      <title>Re: Why does the SearchManager data event fire more than once in Splunk 6.5.2?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Why-does-the-SearchManager-data-event-fire-more-than-once-in/m-p/312490#M4272</link>
      <description>&lt;P&gt;I have accepted that it will always have a risk of occurring and that there is no fix.&lt;/P&gt;

&lt;P&gt;Depending on how you're using the data this might not be effective but this is sloppy pseudo code on how we handled it for now;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;when passing the data into javascript function
set variable counter = 0 
if variable counter == 0 then 
use the data however you want 
counter++
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Now at least it won't loop. &lt;/P&gt;</description>
      <pubDate>Fri, 20 Sep 2019 13:12:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Why-does-the-SearchManager-data-event-fire-more-than-once-in/m-p/312490#M4272</guid>
      <dc:creator>jazzypai</dc:creator>
      <dc:date>2019-09-20T13:12:54Z</dc:date>
    </item>
    <item>
      <title>Re: Why does the SearchManager data event fire more than once in Splunk 6.5.2?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Why-does-the-SearchManager-data-event-fire-more-than-once-in/m-p/312491#M4273</link>
      <description>&lt;P&gt;lol, I see just now that your problem is not my problem. I should go into the weekend &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;My problem is, that I use the searchmanager to execute a search which writes data from the dashboard (basically the dashboards sole reason is collecting user input which can't be automatically collected) into a summary index. &lt;BR /&gt;
There it occurs sometimes that one search results in two events added to the index. In other words the search is executed twice, but not the js code. &lt;/P&gt;

&lt;P&gt;Any idea anyway?&lt;/P&gt;</description>
      <pubDate>Fri, 20 Sep 2019 14:29:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Why-does-the-SearchManager-data-event-fire-more-than-once-in/m-p/312491#M4273</guid>
      <dc:creator>haph</dc:creator>
      <dc:date>2019-09-20T14:29:44Z</dc:date>
    </item>
  </channel>
</rss>

