<?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 substitution string is not working when using the map command to execute a saved search? in Reporting</title>
    <link>https://community.splunk.com/t5/Reporting/Why-is-the-substitution-string-is-not-working-when-using-the-map/m-p/321129#M5800</link>
    <description>&lt;P&gt;hmmm ok so a little confused you are still using the actual saved search name in the map.  My example I provided was not very well expressed my apologies.  Let me go about it like this.&lt;BR /&gt;
index=testindex |stats count by fielda|eval search_name=if(fielda=="John","John Alert","EveryoneElse Alert")&lt;BR /&gt;
|map $search_name$&lt;/P&gt;

&lt;P&gt;So if I get 2 rows back&lt;BR /&gt;
fielda=john saved_search="John Alert"&lt;BR /&gt;
fieldb=joan saved_search="EveroneElse Alert"&lt;/P&gt;

&lt;P&gt;Then I get John Alert executed for the first row.&lt;BR /&gt;
Then EveryoneElse Alert for the second row.&lt;/P&gt;</description>
    <pubDate>Tue, 29 Sep 2020 18:56:17 GMT</pubDate>
    <dc:creator>wfrankl2</dc:creator>
    <dc:date>2020-09-29T18:56:17Z</dc:date>
    <item>
      <title>Why is the substitution string is not working when using the map command to execute a saved search?</title>
      <link>https://community.splunk.com/t5/Reporting/Why-is-the-substitution-string-is-not-working-when-using-the-map/m-p/321127#M5798</link>
      <description>&lt;P&gt;From the documentation&lt;BR /&gt;
"When using a saved search or a literal search, the map command supports the substitution of $variable$ strings that match field names in the input results"&lt;BR /&gt;
So this is a basic example of what I'm trying to do.  The actual work is that I am running a search on some data and with each value returned, if any, would need to execute a different saved search.  So I need to be able to assign the correct saved search name that's used based on a value in the result.  then call the saved search to run.  So I can't hard code the saved search in the map command because it's different for every event.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="testdata" | eval alert="My Test Alert"
   | map $alert$
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 05 Apr 2018 13:43:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/Why-is-the-substitution-string-is-not-working-when-using-the-map/m-p/321127#M5798</guid>
      <dc:creator>wfrankl2</dc:creator>
      <dc:date>2018-04-05T13:43:06Z</dc:date>
    </item>
    <item>
      <title>Re: Why is the substitution string is not working when using the map command to execute a saved search?</title>
      <link>https://community.splunk.com/t5/Reporting/Why-is-the-substitution-string-is-not-working-when-using-the-map/m-p/321128#M5799</link>
      <description>&lt;P&gt;You'll need to combine the &lt;CODE&gt;map&lt;/CODE&gt; command with the &lt;CODE&gt;savedsearch&lt;/CODE&gt; command to reference the saved search in the mapped subsearch. Here's a little demo.&lt;/P&gt;

&lt;P&gt;First, create a saved search called &lt;CODE&gt;test_generate&lt;/CODE&gt;. The code in this saved search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval testfield="test_generate ran"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Then, test loading it in a new search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval search_name="test_generate"
| map search="| savedsearch $search_name$"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This will result in Splunk running your saved search and returning a stats table with the current time and &lt;CODE&gt;testfield="test_generate ran"&lt;/CODE&gt;. This can serve as a template for what you're trying to do.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Apr 2018 15:59:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/Why-is-the-substitution-string-is-not-working-when-using-the-map/m-p/321128#M5799</guid>
      <dc:creator>elliotproebstel</dc:creator>
      <dc:date>2018-04-05T15:59:43Z</dc:date>
    </item>
    <item>
      <title>Re: Why is the substitution string is not working when using the map command to execute a saved search?</title>
      <link>https://community.splunk.com/t5/Reporting/Why-is-the-substitution-string-is-not-working-when-using-the-map/m-p/321129#M5800</link>
      <description>&lt;P&gt;hmmm ok so a little confused you are still using the actual saved search name in the map.  My example I provided was not very well expressed my apologies.  Let me go about it like this.&lt;BR /&gt;
index=testindex |stats count by fielda|eval search_name=if(fielda=="John","John Alert","EveryoneElse Alert")&lt;BR /&gt;
|map $search_name$&lt;/P&gt;

&lt;P&gt;So if I get 2 rows back&lt;BR /&gt;
fielda=john saved_search="John Alert"&lt;BR /&gt;
fieldb=joan saved_search="EveroneElse Alert"&lt;/P&gt;

&lt;P&gt;Then I get John Alert executed for the first row.&lt;BR /&gt;
Then EveryoneElse Alert for the second row.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 18:56:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/Why-is-the-substitution-string-is-not-working-when-using-the-map/m-p/321129#M5800</guid>
      <dc:creator>wfrankl2</dc:creator>
      <dc:date>2020-09-29T18:56:17Z</dc:date>
    </item>
    <item>
      <title>Re: Why is the substitution string is not working when using the map command to execute a saved search?</title>
      <link>https://community.splunk.com/t5/Reporting/Why-is-the-substitution-string-is-not-working-when-using-the-map/m-p/321130#M5801</link>
      <description>&lt;P&gt;Ah, you're right. I didn't carry the variable through, and when I test that now, it doesn't work. I'll keep trying. Sorry about that!&lt;/P&gt;</description>
      <pubDate>Thu, 05 Apr 2018 17:21:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/Why-is-the-substitution-string-is-not-working-when-using-the-map/m-p/321130#M5801</guid>
      <dc:creator>elliotproebstel</dc:creator>
      <dc:date>2018-04-05T17:21:10Z</dc:date>
    </item>
    <item>
      <title>Re: Why is the substitution string is not working when using the map command to execute a saved search?</title>
      <link>https://community.splunk.com/t5/Reporting/Why-is-the-substitution-string-is-not-working-when-using-the-map/m-p/321131#M5802</link>
      <description>&lt;P&gt;Ok, I got it! Here's the revised syntax:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval search_name="test_generate"
| map search="| savedsearch $search_name$"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Give this a try. If it works, I'll update the original answer so you can accept it. &lt;/P&gt;</description>
      <pubDate>Fri, 06 Apr 2018 12:55:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/Why-is-the-substitution-string-is-not-working-when-using-the-map/m-p/321131#M5802</guid>
      <dc:creator>elliotproebstel</dc:creator>
      <dc:date>2018-04-06T12:55:02Z</dc:date>
    </item>
    <item>
      <title>Re: Why is the substitution string is not working when using the map command to execute a saved search?</title>
      <link>https://community.splunk.com/t5/Reporting/Why-is-the-substitution-string-is-not-working-when-using-the-map/m-p/321132#M5803</link>
      <description>&lt;P&gt;hey that worked!!!  Thank you that's perfect!&lt;/P&gt;</description>
      <pubDate>Fri, 06 Apr 2018 14:21:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/Why-is-the-substitution-string-is-not-working-when-using-the-map/m-p/321132#M5803</guid>
      <dc:creator>wfrankl2</dc:creator>
      <dc:date>2018-04-06T14:21:26Z</dc:date>
    </item>
    <item>
      <title>Re: Why is the substitution string is not working when using the map command to execute a saved search?</title>
      <link>https://community.splunk.com/t5/Reporting/Why-is-the-substitution-string-is-not-working-when-using-the-map/m-p/321133#M5804</link>
      <description>&lt;P&gt;Great! I fixed the original answer, so you can accept it. Glad we got it working!&lt;/P&gt;</description>
      <pubDate>Fri, 06 Apr 2018 14:35:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/Why-is-the-substitution-string-is-not-working-when-using-the-map/m-p/321133#M5804</guid>
      <dc:creator>elliotproebstel</dc:creator>
      <dc:date>2018-04-06T14:35:20Z</dc:date>
    </item>
  </channel>
</rss>

