<?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 Can anyone tell me why Splunk is throwing this error when using the foreach command? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Can-anyone-tell-me-why-Splunk-is-throwing-this-error-when-using/m-p/342586#M101479</link>
    <description>&lt;PRE&gt;&lt;CODE&gt;| foreach V* [eval PAC&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;=&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;-Voice], 
| foreach PAC* [eval &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;=if(&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt; &amp;lt; 0, -&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;, 0)]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;error -&amp;gt; Error in 'foreach' command: Only the last argument should be a search pipeline&lt;/P&gt;</description>
    <pubDate>Fri, 03 Nov 2017 08:05:45 GMT</pubDate>
    <dc:creator>nkankur</dc:creator>
    <dc:date>2017-11-03T08:05:45Z</dc:date>
    <item>
      <title>Can anyone tell me why Splunk is throwing this error when using the foreach command?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-anyone-tell-me-why-Splunk-is-throwing-this-error-when-using/m-p/342586#M101479</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;| foreach V* [eval PAC&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;=&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;-Voice], 
| foreach PAC* [eval &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;=if(&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt; &amp;lt; 0, -&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;, 0)]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;error -&amp;gt; Error in 'foreach' command: Only the last argument should be a search pipeline&lt;/P&gt;</description>
      <pubDate>Fri, 03 Nov 2017 08:05:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-anyone-tell-me-why-Splunk-is-throwing-this-error-when-using/m-p/342586#M101479</guid>
      <dc:creator>nkankur</dc:creator>
      <dc:date>2017-11-03T08:05:45Z</dc:date>
    </item>
    <item>
      <title>Re: Can anyone tell me why Splunk is throwing this error when using the foreach command?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-anyone-tell-me-why-Splunk-is-throwing-this-error-when-using/m-p/342587#M101480</link>
      <description>&lt;P&gt;Hi nkankur,&lt;BR /&gt;
I see an odd "," at the end of the first foreach statement... sure this needs to be there?&lt;/P&gt;</description>
      <pubDate>Fri, 03 Nov 2017 08:54:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-anyone-tell-me-why-Splunk-is-throwing-this-error-when-using/m-p/342587#M101480</guid>
      <dc:creator>horsefez</dc:creator>
      <dc:date>2017-11-03T08:54:57Z</dc:date>
    </item>
    <item>
      <title>Re: Can anyone tell me why Splunk is throwing this error when using the foreach command?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Can-anyone-tell-me-why-Splunk-is-throwing-this-error-when-using/m-p/342588#M101481</link>
      <description>&lt;P&gt;I can find 3 issues in above query.&lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;there is a comma &lt;CODE&gt;,&lt;/CODE&gt; in your first line end. That's is wrong&lt;/LI&gt;
&lt;LI&gt;the  string &lt;CODE&gt;-voice&lt;/CODE&gt; should be concatenated to field  using  &lt;CODE&gt;. "&lt;/CODE&gt;  (dot and double quotes) to make it a string.&lt;/LI&gt;
&lt;LI&gt;the PAC value is doing if based on a numeric value, but you have concatenated with a string. This might give unexpected results&lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;Please find corrected query&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|makeresults | eval total=0| eval VariableA="100"| eval VariableB="200"
| foreach V* [eval PAC_&amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;=&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt; . "-voice" ]  
| foreach PAC* [eval &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;=if(&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt; &amp;lt; 0, -&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;, 0)]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 03 Nov 2017 09:56:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Can-anyone-tell-me-why-Splunk-is-throwing-this-error-when-using/m-p/342588#M101481</guid>
      <dc:creator>koshyk</dc:creator>
      <dc:date>2017-11-03T09:56:09Z</dc:date>
    </item>
  </channel>
</rss>

