<?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 Help with putting a conditional in my search in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Help-with-putting-a-conditional-in-my-search/m-p/394872#M114692</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;Someone was kind enough to help me with this yesterday:  &lt;A href="https://answers.splunk.com/answers/738110/how-to-pass-in-a-variable-to-dbxquery.html"&gt;link text&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;And it worked fine, until I realized that there will be times when the base search does not return any events.  I'd like to add some logic to only run the dbxquery if the base search returns one event.  Is there a way to do that?&lt;/P&gt;

&lt;P&gt;Here's the query:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=main sourcetype=ampData_source 
 | fields BATCHSEQUENCE 
 | dedup BATCHSEQUENCE 
 | sort 0 - BATCHSEQUENCE 
 | head 1
 | table BATCHSEQUENCE | map search="| dbxquery query=\"SELECT analyticsutil.closeBatchFunction($BATCHSEQUENCE$,'Y') from dual;\" connection=\"ERPM\"" maxsearches=1
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 10 Apr 2019 11:19:48 GMT</pubDate>
    <dc:creator>a212830</dc:creator>
    <dc:date>2019-04-10T11:19:48Z</dc:date>
    <item>
      <title>Help with putting a conditional in my search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Help-with-putting-a-conditional-in-my-search/m-p/394872#M114692</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;Someone was kind enough to help me with this yesterday:  &lt;A href="https://answers.splunk.com/answers/738110/how-to-pass-in-a-variable-to-dbxquery.html"&gt;link text&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;And it worked fine, until I realized that there will be times when the base search does not return any events.  I'd like to add some logic to only run the dbxquery if the base search returns one event.  Is there a way to do that?&lt;/P&gt;

&lt;P&gt;Here's the query:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=main sourcetype=ampData_source 
 | fields BATCHSEQUENCE 
 | dedup BATCHSEQUENCE 
 | sort 0 - BATCHSEQUENCE 
 | head 1
 | table BATCHSEQUENCE | map search="| dbxquery query=\"SELECT analyticsutil.closeBatchFunction($BATCHSEQUENCE$,'Y') from dual;\" connection=\"ERPM\"" maxsearches=1
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 10 Apr 2019 11:19:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Help-with-putting-a-conditional-in-my-search/m-p/394872#M114692</guid>
      <dc:creator>a212830</dc:creator>
      <dc:date>2019-04-10T11:19:48Z</dc:date>
    </item>
    <item>
      <title>Re: Help with putting a conditional in my search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Help-with-putting-a-conditional-in-my-search/m-p/394873#M114693</link>
      <description>&lt;P&gt;If you are truly not getting any base events to pass the token to the mapped dbxquery, then it should just fail the search with an error "Error in 'map': Did not find value for required attribute 'BATCHSEQUENCE'."  If your goal is not have that error at all then this can accomplish that:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[| makeresults count=1 
    | eval search=if( 
        [ search index=main sourcetype=ampData_source 
        | fields BATCHSEQUENCE 
        | dedup BATCHSEQUENCE 
        | sort 0 - BATCHSEQUENCE 
        | head 1 
        | stats count 
        | return $count]&amp;gt;0, "index=main sourcetype=ampData_source 
| fields BATCHSEQUENCE 
| dedup BATCHSEQUENCE 
| sort 0 - BATCHSEQUENCE 
| head 1
| table BATCHSEQUENCE 
| map search=\"| dbxquery query=\\\"SELECT analyticsutil.closeBatchFunction($BATCHSEQUENCE$,'Y') from dual;\\\" connection=\\\"ERPM\\\"\" maxsearches=1", null()) 
    | table search]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;You will now just get no results instead of an error.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Apr 2019 15:05:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Help-with-putting-a-conditional-in-my-search/m-p/394873#M114693</guid>
      <dc:creator>dmarling</dc:creator>
      <dc:date>2019-04-10T15:05:03Z</dc:date>
    </item>
    <item>
      <title>Re: Help with putting a conditional in my search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Help-with-putting-a-conditional-in-my-search/m-p/394874#M114694</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/215385"&gt;@dmarling&lt;/a&gt; &lt;/P&gt;

&lt;P&gt;I was trying the above solution, but getting the error Unknown search command '0'.&lt;BR /&gt;
My query is:&lt;/P&gt;

&lt;P&gt;[| makeresults count=1 &lt;BR /&gt;
     |eval search=if(&lt;BR /&gt;
[search index="ass_main" host=&lt;EM&gt;pr CASE(4333&lt;/EM&gt;) &lt;BR /&gt;
|  rex field=_raw "(?&amp;lt;EMPID&amp;gt;EMP[0-9]{12})"&lt;BR /&gt;
| fields EMPID&lt;BR /&gt;
| dedup EMPID&lt;BR /&gt;
| sort 0 - EMPID&lt;BR /&gt;
| head 1 &lt;BR /&gt;
| stats count &lt;BR /&gt;
| return $count]&amp;gt;0,"index="ass_main" host=&lt;EM&gt;pr CASE(433&lt;/EM&gt;) &lt;BR /&gt;
| rex field=_raw "(?&amp;lt;EMPID&amp;gt;EMP[0-9]{12})"&lt;BR /&gt;
| fields EMPID&lt;BR /&gt;
| dedup EMPID&lt;BR /&gt;
| stats values(EMPID) as EMPID&lt;BR /&gt;
| eval EMPID= "'".mvjoin(INCID, "','")."'"&lt;BR /&gt;
| map search="| dbxquery query=\"select \\"Emp Number\\",\\"Description\\"&lt;BR /&gt;
                FROM&lt;BR /&gt;
                BIA_BA_EUL.\\"View Emp Helpdesk\\" WHERE \\"Emp Number\\" IN ($EMPID$) \"&lt;BR /&gt;
                connection=\"NTZ-SVC-PR1\"",null())&lt;BR /&gt;
| table search]&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 02:08:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Help-with-putting-a-conditional-in-my-search/m-p/394874#M114694</guid>
      <dc:creator>manunairadavakk</dc:creator>
      <dc:date>2020-09-30T02:08:23Z</dc:date>
    </item>
    <item>
      <title>Re: Help with putting a conditional in my search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Help-with-putting-a-conditional-in-my-search/m-p/394875#M114695</link>
      <description>&lt;P&gt;Hi @manunairadavakkat What version of Splunk are you running?  Can you repost that query in the code sample box so it doesn't escape some of the special characters?  You can do that by hitting Ctrl + K on your key board or clicking the button that has 101010 in the comment GUI.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Sep 2019 17:26:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Help-with-putting-a-conditional-in-my-search/m-p/394875#M114695</guid>
      <dc:creator>dmarling</dc:creator>
      <dc:date>2019-09-05T17:26:15Z</dc:date>
    </item>
  </channel>
</rss>

