<?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 How do I use results from a search in my custom command? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-use-results-from-a-search-in-my-custom-command/m-p/204471#M59392</link>
    <description>&lt;P&gt;I'm trying to use data from a search in a custom command.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;source | scrapy url=uri
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This gives me the following error:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Error in 'scrapy' command: This command must be the first command of a search.
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;It works when I use it as follows:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| scrapy url="www.splunk.com"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;How can I make it work in combination with my search index?&lt;/P&gt;</description>
    <pubDate>Wed, 03 Aug 2016 19:14:56 GMT</pubDate>
    <dc:creator>sjoerdcopier</dc:creator>
    <dc:date>2016-08-03T19:14:56Z</dc:date>
    <item>
      <title>How do I use results from a search in my custom command?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-use-results-from-a-search-in-my-custom-command/m-p/204471#M59392</link>
      <description>&lt;P&gt;I'm trying to use data from a search in a custom command.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;source | scrapy url=uri
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This gives me the following error:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Error in 'scrapy' command: This command must be the first command of a search.
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;It works when I use it as follows:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| scrapy url="www.splunk.com"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;How can I make it work in combination with my search index?&lt;/P&gt;</description>
      <pubDate>Wed, 03 Aug 2016 19:14:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-use-results-from-a-search-in-my-custom-command/m-p/204471#M59392</guid>
      <dc:creator>sjoerdcopier</dc:creator>
      <dc:date>2016-08-03T19:14:56Z</dc:date>
    </item>
    <item>
      <title>Re: How do I use results from a search in my custom command?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-use-results-from-a-search-in-my-custom-command/m-p/204472#M59393</link>
      <description>&lt;P&gt;Since your second search (&lt;CODE&gt;| scrapy url="www.splunk.com"&lt;/CODE&gt;)works, It seems like you've a custom "Generating" search command which is generating the results. &lt;BR /&gt;
For a custom search command to work with your first syntax ( &lt;CODE&gt;source | scrapy url=uri&lt;/CODE&gt;), it should be a non-generating command. See definitions of customer search commands here&lt;BR /&gt;
&lt;A href="http://dev.splunk.com/view/python-sdk/SP-CAAAEU2"&gt;http://dev.splunk.com/view/python-sdk/SP-CAAAEU2&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Aug 2016 19:36:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-use-results-from-a-search-in-my-custom-command/m-p/204472#M59393</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2016-08-03T19:36:54Z</dc:date>
    </item>
    <item>
      <title>Re: How do I use results from a search in my custom command?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-use-results-from-a-search-in-my-custom-command/m-p/204473#M59394</link>
      <description>&lt;P&gt;Hi sjoerdcopier,&lt;/P&gt;

&lt;P&gt;the important thing is to import the &lt;CODE&gt;splunk.Intersplunk&lt;/CODE&gt; module in your script:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;import splunk.Intersplunk
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and read the results from the search into your script:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;myresults,dummyresults,settings = splunk.Intersplunk.getOrganizedResults() # getting search results form Splunk
     for r in myresults: # loop the results
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This way your script can pick up fields from the previous search results and it should work as expected if your search results contain a field called &lt;CODE&gt;url&lt;/CODE&gt; (just rename &lt;CODE&gt;uri&lt;/CODE&gt; to &lt;CODE&gt;url&lt;/CODE&gt;) or change your script to use &lt;CODE&gt;uri&lt;/CODE&gt; instead of &lt;CODE&gt;url&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;The link posted by @somesoni2 provides useful information as well.&lt;/P&gt;

&lt;P&gt;Hope this helps ...&lt;/P&gt;

&lt;P&gt;cheers, MuS&lt;/P&gt;</description>
      <pubDate>Wed, 03 Aug 2016 20:49:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-use-results-from-a-search-in-my-custom-command/m-p/204473#M59394</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2016-08-03T20:49:46Z</dc:date>
    </item>
    <item>
      <title>Re: How do I use results from a search in my custom command?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-use-results-from-a-search-in-my-custom-command/m-p/204474#M59395</link>
      <description>&lt;P&gt;Thanks MuS for your awnser,&lt;BR /&gt;
I can't seem to get this right. Could you be so kind to help me out with an easy example?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;   import splunk.Intersplunk

    # GET DATA FROM SEARCH
    myresults,dummyresults,settings = splunk.Intersplunk.getOrganizedResults() 

    # ILL DO SOME FANCY STUFF HERE

    # SEND DATA BACK
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks for helping out here.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Aug 2016 12:14:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-use-results-from-a-search-in-my-custom-command/m-p/204474#M59395</guid>
      <dc:creator>sjoerdcopier</dc:creator>
      <dc:date>2016-08-04T12:14:43Z</dc:date>
    </item>
    <item>
      <title>Re: How do I use results from a search in my custom command?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-use-results-from-a-search-in-my-custom-command/m-p/204475#M59396</link>
      <description>&lt;P&gt;Take a look at the docs, as usual everything you need is in there &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;This &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.4.2/Search/Customsearchcommandshape"&gt;http://docs.splunk.com/Documentation/Splunk/6.4.2/Search/Customsearchcommandshape&lt;/A&gt; will show an excellent example of a custom command which will use the previous search results, do stuff with it and return something to Splunk.&lt;/P&gt;

&lt;P&gt;cheers, MuS&lt;/P&gt;</description>
      <pubDate>Thu, 04 Aug 2016 20:25:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-use-results-from-a-search-in-my-custom-command/m-p/204475#M59396</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2016-08-04T20:25:19Z</dc:date>
    </item>
  </channel>
</rss>

