<?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 is the 'foreach' command losing event data? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Why-is-the-foreach-command-losing-event-data/m-p/422068#M121222</link>
    <description>&lt;P&gt;Try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;base search
| eval dataReceived=""
| foreach datarcvd_000* [eval dataReceived=if(isnotnull(&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;), dataReceived."&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;"." ".'&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;'." ", dataReceived]
| table _time dataReceived
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 23 Apr 2019 02:01:18 GMT</pubDate>
    <dc:creator>woodcock</dc:creator>
    <dc:date>2019-04-23T02:01:18Z</dc:date>
    <item>
      <title>Why is the 'foreach' command losing event data?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-the-foreach-command-losing-event-data/m-p/422067#M121221</link>
      <description>&lt;P&gt;I'm running Splunk 6.2. I'm dealing with events that have varying amounts of multivalue fields (some events have one, others have up to 12+). The fields follow a &lt;CODE&gt;field_name0001&lt;/CODE&gt;naming convention, like so :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; base search | eval dataReceived="" | foreach datarcvd_000* [eval dataReceived=dataReceived."&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;"." ".'&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;'." " ] | table _time dataReceived
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;When I run this against a week's worth of events, there are several that return nothing in the &lt;CODE&gt;dataReceived&lt;/CODE&gt; field despite the raw event fields being present, and it's always the same handful of events that return null. But what really throws me is that if I filter the base search to return a single uncooperative event, the &lt;CODE&gt;foreach&lt;/CODE&gt; works and it suddenly starts returning data in &lt;CODE&gt;dataReceived&lt;/CODE&gt; as expect. What gives?&lt;/P&gt;</description>
      <pubDate>Mon, 22 Apr 2019 21:40:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-the-foreach-command-losing-event-data/m-p/422067#M121221</guid>
      <dc:creator>jpawloski</dc:creator>
      <dc:date>2019-04-22T21:40:42Z</dc:date>
    </item>
    <item>
      <title>Re: Why is the 'foreach' command losing event data?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-the-foreach-command-losing-event-data/m-p/422068#M121222</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;base search
| eval dataReceived=""
| foreach datarcvd_000* [eval dataReceived=if(isnotnull(&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;), dataReceived."&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;"." ".'&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;'." ", dataReceived]
| table _time dataReceived
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 23 Apr 2019 02:01:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-the-foreach-command-losing-event-data/m-p/422068#M121222</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-04-23T02:01:18Z</dc:date>
    </item>
    <item>
      <title>Re: Why is the 'foreach' command losing event data?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-the-foreach-command-losing-event-data/m-p/422069#M121223</link>
      <description>&lt;P&gt;If any event does not contain ALL possible &lt;CODE&gt;datarcvd_000*&lt;/CODE&gt; values, then your original &lt;CODE&gt;eval&lt;/CODE&gt; will fail.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Apr 2019 02:02:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-the-foreach-command-losing-event-data/m-p/422069#M121223</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-04-23T02:02:17Z</dc:date>
    </item>
    <item>
      <title>Re: Why is the 'foreach' command losing event data?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Why-is-the-foreach-command-losing-event-data/m-p/422070#M121224</link>
      <description>&lt;P&gt;You've done it once again, woodcock. Thanks! &lt;/P&gt;</description>
      <pubDate>Sat, 18 May 2019 11:23:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Why-is-the-foreach-command-losing-event-data/m-p/422070#M121224</guid>
      <dc:creator>jpawloski</dc:creator>
      <dc:date>2019-05-18T11:23:34Z</dc:date>
    </item>
  </channel>
</rss>

