<?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: lookup doesn't work in macro in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/lookup-doesn-t-work-in-macro/m-p/74840#M18904</link>
    <description>&lt;P&gt;Thanks for your answer.&lt;BR /&gt;
I'm sorry, I've updated the macro section of the question with many details but kept the command line in psuedo code. In fact the command line is also doing lookup with userId and I've added this info to the question.&lt;/P&gt;

&lt;P&gt;The fields in weekly cohort are _time, userId, weeklyVisits, firstTime.&lt;/P&gt;

&lt;P&gt;Any ideas?&lt;/P&gt;</description>
    <pubDate>Tue, 01 Jan 2013 08:45:18 GMT</pubDate>
    <dc:creator>dadi</dc:creator>
    <dc:date>2013-01-01T08:45:18Z</dc:date>
    <item>
      <title>lookup doesn't work in macro</title>
      <link>https://community.splunk.com/t5/Splunk-Search/lookup-doesn-t-work-in-macro/m-p/74834#M18898</link>
      <description>&lt;P&gt;hi guys,&lt;BR /&gt;
I've this following command that works perfectly in search query, but doesn't work in macro:&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;.... | lookup myfile.csv userId &lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;The error i get is:&lt;BR /&gt;
"Error in 'lookup' command: Could not find all of the specified lookup fields in the lookup table."&lt;/P&gt;

&lt;P&gt;Does anyone has an idea?&lt;/P&gt;

&lt;P&gt;some more info-&lt;BR /&gt;
the search query is:&lt;BR /&gt;
&lt;CODE&gt;&lt;CODE&gt;cohortCalcVisitsLookup("-4w@w1", "-3w@w1", "@w1", weeklyCohort.csv, "weeklyVisits")&lt;/CODE&gt;&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;and the macro is:&lt;BR /&gt;
&lt;CODE&gt;(index="analytics" table=userSessions  earliest=$start$ latest=$end$) | dedup userId | eval startOfPeriod=relative_time(_time, "$snapTo$")&lt;BR /&gt;
| lookup "$lookupCsv$" userId&lt;BR /&gt;
| eval oldFirstTime=firstTime | eval oldVisits=$visits$&lt;BR /&gt;
| fillnull value=replaceme oldFirstTime&lt;BR /&gt;
| eval $visits$=if(oldFirstTime=="replaceme", startOfPeriod, mvappend(oldVisits , "", startOfPeriod))&lt;BR /&gt;
| &lt;CODE&gt;makemv_withspaces($visits$)&lt;/CODE&gt;&lt;BR /&gt;
| eval firstTime=if(oldFirstTime=="replaceme", startOfPeriod, oldFirstTime) | eval _time=startOfPeriod&lt;BR /&gt;
| table firstTime _time userId $visits$&lt;BR /&gt;
| inputlookup append=true $lookupCsv$ | dedup userId | outputlookup $lookupCsv$ &lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;screenshot:&lt;BR /&gt;
&lt;IMG src="http://i46.tinypic.com/2qk2lcj.png" alt="Alt text" /&gt;&lt;/P&gt;

&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 13:01:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/lookup-doesn-t-work-in-macro/m-p/74834#M18898</guid>
      <dc:creator>dadi</dc:creator>
      <dc:date>2020-09-28T13:01:46Z</dc:date>
    </item>
    <item>
      <title>Re: lookup doesn't work in macro</title>
      <link>https://community.splunk.com/t5/Splunk-Search/lookup-doesn-t-work-in-macro/m-p/74835#M18899</link>
      <description>&lt;P&gt;What app is the macro in? What app are you running in when you do this from the command line?&lt;/P&gt;</description>
      <pubDate>Sun, 30 Dec 2012 22:39:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/lookup-doesn-t-work-in-macro/m-p/74835#M18899</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2012-12-30T22:39:51Z</dc:date>
    </item>
    <item>
      <title>Re: lookup doesn't work in macro</title>
      <link>https://community.splunk.com/t5/Splunk-Search/lookup-doesn-t-work-in-macro/m-p/74836#M18900</link>
      <description>&lt;P&gt;Its the same app. If i search for the lookup inline it works, but if I wrap it in a macro and run it from the same search web page (now only call the macro instead of the explicit lookup call), then it fails with this error.&lt;/P&gt;</description>
      <pubDate>Sun, 30 Dec 2012 22:44:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/lookup-doesn-t-work-in-macro/m-p/74836#M18900</guid>
      <dc:creator>dadi</dc:creator>
      <dc:date>2012-12-30T22:44:06Z</dc:date>
    </item>
    <item>
      <title>Re: lookup doesn't work in macro</title>
      <link>https://community.splunk.com/t5/Splunk-Search/lookup-doesn-t-work-in-macro/m-p/74837#M18901</link>
      <description>&lt;P&gt;Can you show the complete text of the macro - and also the complete command line using the macro?&lt;/P&gt;

&lt;P&gt;What do you see when you use the Search Job Inspector? It usually shows the macro expansion  - so you cn see the full search string.&lt;/P&gt;</description>
      <pubDate>Sun, 30 Dec 2012 22:58:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/lookup-doesn-t-work-in-macro/m-p/74837#M18901</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2012-12-30T22:58:28Z</dc:date>
    </item>
    <item>
      <title>Re: lookup doesn't work in macro</title>
      <link>https://community.splunk.com/t5/Splunk-Search/lookup-doesn-t-work-in-macro/m-p/74838#M18902</link>
      <description>&lt;P&gt;added info in question. Thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 31 Dec 2012 06:27:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/lookup-doesn-t-work-in-macro/m-p/74838#M18902</guid>
      <dc:creator>dadi</dc:creator>
      <dc:date>2012-12-31T06:27:50Z</dc:date>
    </item>
    <item>
      <title>Re: lookup doesn't work in macro</title>
      <link>https://community.splunk.com/t5/Splunk-Search/lookup-doesn-t-work-in-macro/m-p/74839#M18903</link>
      <description>&lt;P&gt;This is what you said you did on the command line:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;.... | lookup myfile.csv 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But this is what the macro does:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | lookup "$lookupCsv$" userId
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Expanded in to the example used in the screenshot, it would be&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | lookup "weeklyCohort.csv" userId
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;-- assuming that your macro arguments are in the correct order.&lt;BR /&gt;&lt;BR /&gt;
These do not look the same to me at all.&lt;/P&gt;

&lt;P&gt;Also, what fields are in the &lt;CODE&gt;weeklyCohort.csv&lt;/CODE&gt; file?&lt;/P&gt;</description>
      <pubDate>Mon, 31 Dec 2012 19:11:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/lookup-doesn-t-work-in-macro/m-p/74839#M18903</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2012-12-31T19:11:09Z</dc:date>
    </item>
    <item>
      <title>Re: lookup doesn't work in macro</title>
      <link>https://community.splunk.com/t5/Splunk-Search/lookup-doesn-t-work-in-macro/m-p/74840#M18904</link>
      <description>&lt;P&gt;Thanks for your answer.&lt;BR /&gt;
I'm sorry, I've updated the macro section of the question with many details but kept the command line in psuedo code. In fact the command line is also doing lookup with userId and I've added this info to the question.&lt;/P&gt;

&lt;P&gt;The fields in weekly cohort are _time, userId, weeklyVisits, firstTime.&lt;/P&gt;

&lt;P&gt;Any ideas?&lt;/P&gt;</description>
      <pubDate>Tue, 01 Jan 2013 08:45:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/lookup-doesn-t-work-in-macro/m-p/74840#M18904</guid>
      <dc:creator>dadi</dc:creator>
      <dc:date>2013-01-01T08:45:18Z</dc:date>
    </item>
    <item>
      <title>Re: lookup doesn't work in macro</title>
      <link>https://community.splunk.com/t5/Splunk-Search/lookup-doesn-t-work-in-macro/m-p/74841#M18905</link>
      <description>&lt;P&gt;Weird - I have no idea why it doesn't work! BUT, I do have ideas about how to figure it out - apologies if you have already tried these.&lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;Copy off the first part of the macro, including the lookup command, into a new macro.&lt;BR /&gt;&lt;/LI&gt;
&lt;LI&gt;Run the new macro and use the Search Job Inspector to look at how it parsed.&lt;BR /&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;P&gt;Run the first part from the command line as well, again using the inspector.&lt;/P&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;P&gt;Try explicitly naming the output fields:&lt;BR /&gt;&lt;BR /&gt;
&lt;CODE&gt;lookup lookup "$lookupCsv$" userId  OUTPUT _time as eTime weeklyVisits firstTime&lt;/CODE&gt;&lt;/P&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;P&gt;Note that I have renamed the &lt;CODE&gt;_time&lt;/CODE&gt; field, so that it does not conflict with the existing field. I am not sure if this is causing the problem, but you were potentially overwriting a built-in field...  &lt;/P&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;P&gt;If none of this works, then I am out of ideas. I'd suggest that you file a support ticket. Or perhaps someone else will know the answer.&lt;/P&gt;&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Tue, 01 Jan 2013 15:53:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/lookup-doesn-t-work-in-macro/m-p/74841#M18905</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2013-01-01T15:53:50Z</dc:date>
    </item>
    <item>
      <title>Re: lookup doesn't work in macro</title>
      <link>https://community.splunk.com/t5/Splunk-Search/lookup-doesn-t-work-in-macro/m-p/74842#M18906</link>
      <description>&lt;P&gt;after some more investigation - It seems that the problem is not in the lookup command but rather on the next phase when I'm taking one of the lookup output parameter and try to use them ($visits$ in my example). If I inline this parameter then it works&lt;/P&gt;</description>
      <pubDate>Wed, 02 Jan 2013 10:16:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/lookup-doesn-t-work-in-macro/m-p/74842#M18906</guid>
      <dc:creator>dadi</dc:creator>
      <dc:date>2013-01-02T10:16:25Z</dc:date>
    </item>
    <item>
      <title>Re: lookup doesn't work in macro</title>
      <link>https://community.splunk.com/t5/Splunk-Search/lookup-doesn-t-work-in-macro/m-p/74843#M18907</link>
      <description>&lt;P&gt;Hmm, that was a crummy error message from Splunk - it really pointed at the lookup command!!&lt;/P&gt;</description>
      <pubDate>Wed, 02 Jan 2013 16:15:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/lookup-doesn-t-work-in-macro/m-p/74843#M18907</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2013-01-02T16:15:56Z</dc:date>
    </item>
  </channel>
</rss>

