<?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: Eval If statement with searches as arguments in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Eval-If-statement-with-searches-as-arguments/m-p/296865#M160288</link>
    <description>&lt;P&gt;An &lt;CODE&gt;eval&lt;/CODE&gt; doesn't work that way.  &lt;CODE&gt;result&lt;/CODE&gt; is a variable, and table variables don't exist in splunk, as far as I know.  &lt;/P&gt;

&lt;P&gt;You can achieve the same thing, though, with &lt;CODE&gt;map&lt;/CODE&gt;.  &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval result= if(var1=="All", "search language for search1", "search language for search2")
| map search="$result$"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 06 Jul 2017 13:38:34 GMT</pubDate>
    <dc:creator>DalJeanis</dc:creator>
    <dc:date>2017-07-06T13:38:34Z</dc:date>
    <item>
      <title>Eval If statement with searches as arguments</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Eval-If-statement-with-searches-as-arguments/m-p/296863#M160286</link>
      <description>&lt;P&gt;I am using the eval as follows:&lt;/P&gt;

&lt;P&gt;eval result= if(var1=="All", [search1], [search2])&lt;/P&gt;

&lt;P&gt;where search1 and search2 both return tables. According the whether the if condition is satisfied or not I display either one of the tables. The error which I am getting when I execute the above query is:&lt;/P&gt;

&lt;P&gt;Error in 'eval' command: The expression is malformed. An unexpected character is reached at ').&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jul 2017 02:27:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Eval-If-statement-with-searches-as-arguments/m-p/296863#M160286</guid>
      <dc:creator>nisha_kapoor</dc:creator>
      <dc:date>2017-07-06T02:27:55Z</dc:date>
    </item>
    <item>
      <title>Re: Eval If statement with searches as arguments</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Eval-If-statement-with-searches-as-arguments/m-p/296864#M160287</link>
      <description>&lt;P&gt;@nisha_kapoor, how is var1=="All" or var1!="All" set. Is this coming from an input or existing search. Please provide a background of your use case, as there could be multiple solutions to this problem.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jul 2017 13:32:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Eval-If-statement-with-searches-as-arguments/m-p/296864#M160287</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-07-06T13:32:40Z</dc:date>
    </item>
    <item>
      <title>Re: Eval If statement with searches as arguments</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Eval-If-statement-with-searches-as-arguments/m-p/296865#M160288</link>
      <description>&lt;P&gt;An &lt;CODE&gt;eval&lt;/CODE&gt; doesn't work that way.  &lt;CODE&gt;result&lt;/CODE&gt; is a variable, and table variables don't exist in splunk, as far as I know.  &lt;/P&gt;

&lt;P&gt;You can achieve the same thing, though, with &lt;CODE&gt;map&lt;/CODE&gt;.  &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval result= if(var1=="All", "search language for search1", "search language for search2")
| map search="$result$"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 06 Jul 2017 13:38:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Eval-If-statement-with-searches-as-arguments/m-p/296865#M160288</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-07-06T13:38:34Z</dc:date>
    </item>
    <item>
      <title>Re: Eval If statement with searches as arguments</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Eval-If-statement-with-searches-as-arguments/m-p/296866#M160289</link>
      <description>&lt;P&gt;Like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; [ Some Search Here | head 1 | eval search=if(var1=="All", "search language for search1", "search language for search2") | table search ]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 06 Jul 2017 15:52:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Eval-If-statement-with-searches-as-arguments/m-p/296866#M160289</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2017-07-06T15:52:49Z</dc:date>
    </item>
    <item>
      <title>Re: Eval If statement with searches as arguments</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Eval-If-statement-with-searches-as-arguments/m-p/296867#M160290</link>
      <description>&lt;P&gt;@woodcock - Cool!  Context, please?  Like, exactly what has to be in place for this elegant little strategy to work?&lt;/P&gt;

&lt;P&gt;This is going to return a variable named &lt;CODE&gt;search&lt;/CODE&gt; with a value like &lt;CODE&gt;search language for search1&lt;/CODE&gt;, so it seems like it will work when it is the &lt;EM&gt;entire&lt;/EM&gt; search.  Any other places it will work?  &lt;/P&gt;</description>
      <pubDate>Thu, 06 Jul 2017 18:34:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Eval-If-statement-with-searches-as-arguments/m-p/296867#M160290</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-07-06T18:34:35Z</dc:date>
    </item>
    <item>
      <title>Re: Eval If statement with searches as arguments</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Eval-If-statement-with-searches-as-arguments/m-p/296868#M160291</link>
      <description>&lt;P&gt;var1 is coming from a form input (dropdown). If that value is equal to "All" a run a certain search on my index and display the table else I run a different search and display that table. The issue I am facing is that I think only numbers/strings and not tables can be returned as arguments to an eval statement.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jul 2017 21:09:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Eval-If-statement-with-searches-as-arguments/m-p/296868#M160291</guid>
      <dc:creator>nisha_kapoor</dc:creator>
      <dc:date>2017-07-06T21:09:27Z</dc:date>
    </item>
    <item>
      <title>Re: Eval If statement with searches as arguments</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Eval-If-statement-with-searches-as-arguments/m-p/296869#M160292</link>
      <description>&lt;P&gt;This is just the &lt;CODE&gt;subsearch&lt;/CODE&gt; side of your &lt;CODE&gt;map&lt;/CODE&gt; coin.  Almost anything that you can do with &lt;CODE&gt;map&lt;/CODE&gt;, templating wise, you can also do with a &lt;CODE&gt;subsearch&lt;/CODE&gt; by turning the design "inside-out".&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jul 2017 21:39:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Eval-If-statement-with-searches-as-arguments/m-p/296869#M160292</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2017-07-06T21:39:13Z</dc:date>
    </item>
    <item>
      <title>Re: Eval If statement with searches as arguments</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Eval-If-statement-with-searches-as-arguments/m-p/296870#M160293</link>
      <description>&lt;P&gt;This is what I tried originally, but it gives me this error&lt;/P&gt;

&lt;P&gt;Error in 'eval' command: The expression is malformed. An unexpected character is reached at ') , ( ( row1 of search) OR (row2 of search) OR (row 3 of search) ) ) )'.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jul 2017 21:46:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Eval-If-statement-with-searches-as-arguments/m-p/296870#M160293</guid>
      <dc:creator>nisha_kapoor</dc:creator>
      <dc:date>2017-07-06T21:46:06Z</dc:date>
    </item>
    <item>
      <title>Re: Eval If statement with searches as arguments</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Eval-If-statement-with-searches-as-arguments/m-p/296871#M160294</link>
      <description>&lt;P&gt;I tried this and now this is the error I am getting &lt;/P&gt;

&lt;P&gt;Error in 'eval' command: The expression is malformed. Expected ).&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jul 2017 22:00:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Eval-If-statement-with-searches-as-arguments/m-p/296871#M160294</guid>
      <dc:creator>nisha_kapoor</dc:creator>
      <dc:date>2017-07-06T22:00:24Z</dc:date>
    </item>
    <item>
      <title>Re: Eval If statement with searches as arguments</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Eval-If-statement-with-searches-as-arguments/m-p/296872#M160295</link>
      <description>&lt;P&gt;If your search strings include double-quote characters &lt;CODE&gt;"&lt;/CODE&gt;, you will have to escape each one with a backslash .&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jul 2017 22:03:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Eval-If-statement-with-searches-as-arguments/m-p/296872#M160295</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2017-07-06T22:03:50Z</dc:date>
    </item>
    <item>
      <title>Re: Eval If statement with searches as arguments</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Eval-If-statement-with-searches-as-arguments/m-p/296873#M160296</link>
      <description>&lt;P&gt;Oh okay, I did that too and the error has disappeared, but now instead of the data, the search string is repeated over and over again in the result table.&lt;/P&gt;

&lt;P&gt;This is the query with the modifications:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="test_data"| eval search= if(var1!= "All" , "search index=\"test_data\" extracted_Source=\"*\" Target=\"*\" 
Status=\"*\" Name=\"*\" col1=\"*\"  | table Name extracted_Source Target Status Details CreatedAt | sort -CreatedAt Time" ,
"search index=\"test_data\" extracted_Source=\"*\" Target=\"*\" Status=\"*\" Name=\"*\" 
| table Name extracted_Source Target Status Details CreatedAt | sort -CreatedAt Time")| table search
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 06 Jul 2017 22:18:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Eval-If-statement-with-searches-as-arguments/m-p/296873#M160296</guid>
      <dc:creator>nisha_kapoor</dc:creator>
      <dc:date>2017-07-06T22:18:35Z</dc:date>
    </item>
    <item>
      <title>Re: Eval If statement with searches as arguments</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Eval-If-statement-with-searches-as-arguments/m-p/296874#M160297</link>
      <description>&lt;P&gt;@nisha_kapoor, you can code the &lt;STRONG&gt;change&lt;/STRONG&gt; event of the dropdown and pass on the Search query as token (&lt;STRONG&gt;queryString&lt;/STRONG&gt; in the following example) based on selected value in the dropdown.&lt;/P&gt;

&lt;P&gt;Following is a run anywhere example:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;row&amp;gt;
   &amp;lt;panel&amp;gt;
      &amp;lt;input type="dropdown" token="var1" searchWhenChanged="true"&amp;gt;
          &amp;lt;label&amp;gt;Select Value&amp;lt;/label&amp;gt;
          &amp;lt;choice value="All"&amp;gt;All&amp;lt;/choice&amp;gt;
          &amp;lt;choice value="Other"&amp;gt;Other&amp;lt;/choice&amp;gt;
             &amp;lt;change&amp;gt;
                &amp;lt;condition value="All"&amp;gt;
                    &amp;lt;set token="queryString"&amp;gt;index=_internal sourcetype=splunkd log_level!="INFO" | stats count by log_level&amp;lt;/set&amp;gt;
                &amp;lt;/condition&amp;gt;
                &amp;lt;condition&amp;gt;
                    &amp;lt;set token="queryString"&amp;gt;| makeresults | eval msg="$value$ value selected"&amp;lt;/set&amp;gt;
                &amp;lt;/condition&amp;gt;
             &amp;lt;/change&amp;gt;
             &amp;lt;default&amp;gt;All&amp;lt;/default&amp;gt;
          &amp;lt;/input&amp;gt;
          &amp;lt;table&amp;gt;
               &amp;lt;search&amp;gt;
                   &amp;lt;query&amp;gt;$queryString$&amp;lt;/query&amp;gt;
                   &amp;lt;earliest&amp;gt;-24h@h&amp;lt;/earliest&amp;gt;
                   &amp;lt;latest&amp;gt;now&amp;lt;/latest&amp;gt;
               &amp;lt;/search&amp;gt;
                &amp;lt;option name="count"&amp;gt;5&amp;lt;/option&amp;gt;
                &amp;lt;option name="wrap"&amp;gt;true&amp;lt;/option&amp;gt;
                &amp;lt;option name="drilldown"&amp;gt;none&amp;lt;/option&amp;gt;
                &amp;lt;option name="dataOverlayMode"&amp;gt;none&amp;lt;/option&amp;gt;
          &amp;lt;/table&amp;gt;
   &amp;lt;/panel&amp;gt;
&amp;lt;/row&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 07 Jul 2017 06:31:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Eval-If-statement-with-searches-as-arguments/m-p/296874#M160297</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-07-07T06:31:01Z</dc:date>
    </item>
    <item>
      <title>Re: Eval If statement with searches as arguments</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Eval-If-statement-with-searches-as-arguments/m-p/296875#M160298</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[ index="test_data" 
| head 1
| eval search=if((var1!= "All"), "index=\"test_data\" extracted_Source=\"*\" Target=\"*\" Status=\"*\" Name=\"*\" col1=\"*\" | table Name extracted_Source Target Status Details CreatedAt | sort -CreatedAt Time" , "index=\"test_data\" extracted_Source=\"*\" Target=\"*\" Status=\"*\" Name=\"*\" | table Name extracted_Source Target Status Details CreatedAt | sort -CreatedAt Time") | table search ]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 07 Jul 2017 20:28:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Eval-If-statement-with-searches-as-arguments/m-p/296875#M160298</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2017-07-07T20:28:11Z</dc:date>
    </item>
    <item>
      <title>Re: Eval If statement with searches as arguments</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Eval-If-statement-with-searches-as-arguments/m-p/296876#M160299</link>
      <description>&lt;P&gt;This doesn't seem to be working. I want that if I put a value instead of *, the results should be filtered based on that criteria. However, the above command simply seems to be getting me all the results stored in "test_data" and returning the top one. &lt;/P&gt;

&lt;P&gt;This is another way I tried, &lt;/P&gt;

&lt;P&gt;index="test_data" extracted_Source="$field4$" Target="$field5$" &lt;BR /&gt;
Status="$field7$" Name="$field8$"  ($field1$ != "All" AND $field1$="$field2$") OR ($field1$==All AND TransactionID ="*") | table TransactionID Name extracted_Source Target Status Details CreatedAt&lt;/P&gt;

&lt;P&gt;The first part of this works fine as in the filter criteria (field1=field2) gets appended to the initial search when $field1$!= All. However, the second condition($field1$==All) is never satisfied. &lt;/P&gt;

&lt;P&gt;Can someone help me on how to compare the value of a field to a string and return true?&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 14:46:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Eval-If-statement-with-searches-as-arguments/m-p/296876#M160299</guid>
      <dc:creator>nisha_kapoor</dc:creator>
      <dc:date>2020-09-29T14:46:49Z</dc:date>
    </item>
    <item>
      <title>Re: Eval If statement with searches as arguments</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Eval-If-statement-with-searches-as-arguments/m-p/296877#M160300</link>
      <description>&lt;P&gt;This seems to work perfectly, thank you!&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jul 2017 21:19:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Eval-If-statement-with-searches-as-arguments/m-p/296877#M160300</guid>
      <dc:creator>nisha_kapoor</dc:creator>
      <dc:date>2017-07-07T21:19:22Z</dc:date>
    </item>
    <item>
      <title>Re: Eval If statement with searches as arguments</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Eval-If-statement-with-searches-as-arguments/m-p/296878#M160301</link>
      <description>&lt;P&gt;This seems to achieve what I was looking for, but there is one glitch. When I select a new option, the results don't load until I manually refresh my browser. Is there some way around this, since I don't want my users to have to refresh the browser each time they select a different option.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jul 2017 21:42:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Eval-If-statement-with-searches-as-arguments/m-p/296878#M160301</guid>
      <dc:creator>nisha_kapoor</dc:creator>
      <dc:date>2017-07-07T21:42:41Z</dc:date>
    </item>
    <item>
      <title>Re: Eval If statement with searches as arguments</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Eval-If-statement-with-searches-as-arguments/m-p/296879#M160302</link>
      <description>&lt;P&gt;Can you ensure that searchWhenChanged is set to true for the drop down?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;   &amp;lt;input type="dropdown" token="var1" searchWhenChanged="true"&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 08 Jul 2017 00:38:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Eval-If-statement-with-searches-as-arguments/m-p/296879#M160302</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-07-08T00:38:28Z</dc:date>
    </item>
    <item>
      <title>Re: Eval If statement with searches as arguments</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Eval-If-statement-with-searches-as-arguments/m-p/296880#M160303</link>
      <description>&lt;P&gt;Yeah my searchWhenChanged option is set to true, however the queryString doesn't get updated. It uses the previously stored value when it is passed to the search panel.&lt;/P&gt;</description>
      <pubDate>Sat, 08 Jul 2017 01:36:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Eval-If-statement-with-searches-as-arguments/m-p/296880#M160303</guid>
      <dc:creator>nisha_kapoor</dc:creator>
      <dc:date>2017-07-08T01:36:40Z</dc:date>
    </item>
    <item>
      <title>Re: Eval If statement with searches as arguments</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Eval-If-statement-with-searches-as-arguments/m-p/296881#M160304</link>
      <description>&lt;P&gt;Which version of Splunk are you on. Is Autorun dashboard enabled?&lt;/P&gt;</description>
      <pubDate>Sat, 08 Jul 2017 05:27:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Eval-If-statement-with-searches-as-arguments/m-p/296881#M160304</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-07-08T05:27:16Z</dc:date>
    </item>
    <item>
      <title>Re: Eval If statement with searches as arguments</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Eval-If-statement-with-searches-as-arguments/m-p/296882#M160305</link>
      <description>&lt;P&gt;Hi I am on Splunk Enterprise and my Autorun dashboard is on. The search refreshes when a new option is selected from the dropdown, the only problem is that querystring retains the previous dropdown value.&lt;/P&gt;

&lt;P&gt;So suppose I open my search and the default value of the dropdown is "a". I select value as "b" and click submit(autorun and search on change are also on), the querystring still searches with "a" instead of "b" until I refresh the browser or change my selection again.&lt;/P&gt;</description>
      <pubDate>Sat, 08 Jul 2017 20:07:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Eval-If-statement-with-searches-as-arguments/m-p/296882#M160305</guid>
      <dc:creator>nisha_kapoor</dc:creator>
      <dc:date>2017-07-08T20:07:14Z</dc:date>
    </item>
  </channel>
</rss>

