<?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: Pass a variable to fields command in a search - not working in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Pass-a-variable-to-fields-command-in-a-search-not-working/m-p/301364#M90751</link>
    <description>&lt;P&gt;Put the fieldName in double quotes as you need to pass it as string.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[| makeresults | eval search="fieldNames"]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 11 Apr 2018 19:26:45 GMT</pubDate>
    <dc:creator>somesoni2</dc:creator>
    <dc:date>2018-04-11T19:26:45Z</dc:date>
    <item>
      <title>Pass a variable to fields command in a search - not working</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Pass-a-variable-to-fields-command-in-a-search-not-working/m-p/301359#M90746</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I'm trying to build a mechanism to pre-define a set of fields in my searches. The mechanism normally uses a macro and a lookup table to create a list of fields and this part is working fine. The problem is that it seems the "fields" command can't use my list correctly. For instance:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="main" 
| eval myfieldslist="host,sourcetype,source" 
| fields $myfieldslist$
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;That looks good to me but it only shows the _time field which means the "fields" command does consider the string "host,sourcetype,source" as a unique value and not as a list of values. I tried different things but I can't make it work.&lt;/P&gt;

&lt;P&gt;Any help would be appreciated&lt;BR /&gt;
Thank you&lt;/P&gt;</description>
      <pubDate>Fri, 25 Aug 2017 11:59:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Pass-a-variable-to-fields-command-in-a-search-not-working/m-p/301359#M90746</guid>
      <dc:creator>cardinalga</dc:creator>
      <dc:date>2017-08-25T11:59:37Z</dc:date>
    </item>
    <item>
      <title>Re: Pass a variable to fields command in a search - not working</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Pass-a-variable-to-fields-command-in-a-search-not-working/m-p/301360#M90747</link>
      <description>&lt;P&gt;Try like this (the subsearch will get the string placed in fields command. The field name &lt;CODE&gt;search&lt;/CODE&gt; is special field that returns the string value. You can replace the searchsearch with your current search/logic, just rename the field that contains field names to search)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="main" 
| fields [| gentimes start=-1 | eval search="host,sourcetype,source" | table search]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 25 Aug 2017 15:06:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Pass-a-variable-to-fields-command-in-a-search-not-working/m-p/301360#M90747</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2017-08-25T15:06:19Z</dc:date>
    </item>
    <item>
      <title>Re: Pass a variable to fields command in a search - not working</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Pass-a-variable-to-fields-command-in-a-search-not-working/m-p/301361#M90748</link>
      <description>&lt;P&gt;Thank you so much, it is very helpful. &lt;/P&gt;

&lt;P&gt;Actually I'm pretty close of what I wanted, I just don't understand why I only have 1 field in the "selected_fields" group (displayed as a column in the right search pane showing the events) and the others being in the "interesting_fields" group and not displayed.  However it seems I will be able to get them all displayed as expected by playing with a few more table/fields parameters&lt;/P&gt;

&lt;P&gt;Thx again&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 15:30:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Pass-a-variable-to-fields-command-in-a-search-not-working/m-p/301361#M90748</guid>
      <dc:creator>cardinalga</dc:creator>
      <dc:date>2020-09-29T15:30:59Z</dc:date>
    </item>
    <item>
      <title>Re: Pass a variable to fields command in a search - not working</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Pass-a-variable-to-fields-command-in-a-search-not-working/m-p/301362#M90749</link>
      <description>&lt;P&gt;Another solution:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="main"  
| fields [| makeresults | eval search="host,sourcetype,source" ]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 31 Aug 2017 08:42:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Pass-a-variable-to-fields-command-in-a-search-not-working/m-p/301362#M90749</guid>
      <dc:creator>cardinalga</dc:creator>
      <dc:date>2017-08-31T08:42:40Z</dc:date>
    </item>
    <item>
      <title>Re: Pass a variable to fields command in a search - not working</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Pass-a-variable-to-fields-command-in-a-search-not-working/m-p/301363#M90750</link>
      <description>&lt;P&gt;I'm trying to pass an eval field to this, but it doesn't work: is there something I'm missing?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval fieldNames="" | eval fieldNames=if(isnull(fieldA), fieldNames."fieldA,fieldB", fieldNames)
| fields - [| makeresults | eval search=fieldNames]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 11 Apr 2018 19:20:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Pass-a-variable-to-fields-command-in-a-search-not-working/m-p/301363#M90750</guid>
      <dc:creator>haraksin</dc:creator>
      <dc:date>2018-04-11T19:20:37Z</dc:date>
    </item>
    <item>
      <title>Re: Pass a variable to fields command in a search - not working</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Pass-a-variable-to-fields-command-in-a-search-not-working/m-p/301364#M90751</link>
      <description>&lt;P&gt;Put the fieldName in double quotes as you need to pass it as string.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[| makeresults | eval search="fieldNames"]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 11 Apr 2018 19:26:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Pass-a-variable-to-fields-command-in-a-search-not-working/m-p/301364#M90751</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2018-04-11T19:26:45Z</dc:date>
    </item>
    <item>
      <title>Re: Pass a variable to fields command in a search - not working</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Pass-a-variable-to-fields-command-in-a-search-not-working/m-p/301365#M90752</link>
      <description>&lt;P&gt;It's a variable I'm defining earlier, not a string I want to pass. "fieldA,fieldB" is the string I want to pass.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Apr 2018 19:30:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Pass-a-variable-to-fields-command-in-a-search-not-working/m-p/301365#M90752</guid>
      <dc:creator>haraksin</dc:creator>
      <dc:date>2018-04-11T19:30:21Z</dc:date>
    </item>
    <item>
      <title>Re: Pass a variable to fields command in a search - not working</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Pass-a-variable-to-fields-command-in-a-search-not-working/m-p/301366#M90753</link>
      <description>&lt;P&gt;You can't pass a field or value from main search to a subsearch, that'll not work.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Apr 2018 19:44:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Pass-a-variable-to-fields-command-in-a-search-not-working/m-p/301366#M90753</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2018-04-11T19:44:05Z</dc:date>
    </item>
    <item>
      <title>Re: Pass a variable to fields command in a search - not working</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Pass-a-variable-to-fields-command-in-a-search-not-working/m-p/301367#M90754</link>
      <description>&lt;P&gt;I wasn't aware this is the case; thanks for the help! If you have any suggestions without the subsearch, then that would be awesome, but if not, I still appreciate your help.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Apr 2018 19:51:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Pass-a-variable-to-fields-command-in-a-search-not-working/m-p/301367#M90754</guid>
      <dc:creator>haraksin</dc:creator>
      <dc:date>2018-04-11T19:51:36Z</dc:date>
    </item>
    <item>
      <title>Re: Pass a variable to fields command in a search - not working</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Pass-a-variable-to-fields-command-in-a-search-not-working/m-p/301368#M90755</link>
      <description>&lt;P&gt;@haraksin if your use case is different you can post your question on Splunk Answers with the required details as to what you are trying to do and what is not working. Is this for a dashboard?&lt;/P&gt;</description>
      <pubDate>Thu, 12 Apr 2018 04:30:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Pass-a-variable-to-fields-command-in-a-search-not-working/m-p/301368#M90755</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2018-04-12T04:30:34Z</dc:date>
    </item>
  </channel>
</rss>

