<?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: How to pass field values as macro arguments? in Knowledge Management</title>
    <link>https://community.splunk.com/t5/Knowledge-Management/How-to-pass-field-values-as-macro-arguments/m-p/678919#M9899</link>
    <description>&lt;P&gt;I am browsing to look for a solution to this issue and eventually accidentally found a solution myself. Try if this will work for you.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;search sourcetype=type1 field1='$arg1$' | rename field2 as query | fields query | eval newField=query&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Single quotes will return the value of the field in an eval expression.&lt;/P&gt;</description>
    <pubDate>Wed, 28 Feb 2024 05:02:27 GMT</pubDate>
    <dc:creator>darljedmatundan</dc:creator>
    <dc:date>2024-02-28T05:02:27Z</dc:date>
    <item>
      <title>How to pass field values as macro arguments?</title>
      <link>https://community.splunk.com/t5/Knowledge-Management/How-to-pass-field-values-as-macro-arguments/m-p/164018#M1570</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I am trying to pass a field as an argument for a macro that I have defined, but it's not working.&lt;BR /&gt;
My macro looks like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[search sourcetype=type1 field1=$arg1$ | rename field2 as query | fields query | head 1]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;My query is:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=type2|eval newField=`newMacro(field3)`|table newField,field3
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If I pass a value (e.g: &lt;CODE&gt;newMacro(0001)&lt;/CODE&gt;) it works. Can someone tell me how to pass field3 as an argument?&lt;BR /&gt;
Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 23 Apr 2015 13:02:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Knowledge-Management/How-to-pass-field-values-as-macro-arguments/m-p/164018#M1570</guid>
      <dc:creator>andra_pietraru</dc:creator>
      <dc:date>2015-04-23T13:02:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass field values as macro arguments?</title>
      <link>https://community.splunk.com/t5/Knowledge-Management/How-to-pass-field-values-as-macro-arguments/m-p/164019#M1571</link>
      <description>&lt;P&gt;Your eval should be in the macro, so you'd just call it and pass it field3. i.e.:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; sourcetype=type2|`newMacro(field3)`|table newField,field3
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Let me know if you need help with the macro itself.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Apr 2015 13:57:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Knowledge-Management/How-to-pass-field-values-as-macro-arguments/m-p/164019#M1571</guid>
      <dc:creator>masonmorales</dc:creator>
      <dc:date>2015-04-23T13:57:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass field values as macro arguments?</title>
      <link>https://community.splunk.com/t5/Knowledge-Management/How-to-pass-field-values-as-macro-arguments/m-p/164020#M1572</link>
      <description>&lt;P&gt;I would like to get an idea for the macro as well.&lt;BR /&gt;
Now the macro I have looks like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;search sourcetype=type1 field1=$arg1$ | rename field2 as query | fields query | eval newField=query
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 23 Apr 2015 14:12:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Knowledge-Management/How-to-pass-field-values-as-macro-arguments/m-p/164020#M1572</guid>
      <dc:creator>andra_pietraru</dc:creator>
      <dc:date>2015-04-23T14:12:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass field values as macro arguments?</title>
      <link>https://community.splunk.com/t5/Knowledge-Management/How-to-pass-field-values-as-macro-arguments/m-p/164021#M1573</link>
      <description>&lt;P&gt;Try changing it to &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;appendcols [ search sourcetype=type1 field1=$arg1$ | rename field2 as query | fields query | eval newField=query]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;or&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;append [ search sourcetype=type1 field1=$arg1$ | rename field2 as query | fields query | eval newField=query]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 23 Apr 2015 15:39:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Knowledge-Management/How-to-pass-field-values-as-macro-arguments/m-p/164021#M1573</guid>
      <dc:creator>masonmorales</dc:creator>
      <dc:date>2015-04-23T15:39:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass field values as macro arguments?</title>
      <link>https://community.splunk.com/t5/Knowledge-Management/How-to-pass-field-values-as-macro-arguments/m-p/164022#M1574</link>
      <description>&lt;P&gt;I tried both. The first one gives error :"Error in 'appendcols' command: You can only use appendcols after a reporting command (such as stats, chart, or timechart)".&lt;BR /&gt;
The second one doesn't give error. But the &lt;EM&gt;newField&lt;/EM&gt; column is empty. Any ideas why? Could it be because I have two different sourcetypes?&lt;/P&gt;</description>
      <pubDate>Fri, 24 Apr 2015 06:46:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Knowledge-Management/How-to-pass-field-values-as-macro-arguments/m-p/164022#M1574</guid>
      <dc:creator>andra_pietraru</dc:creator>
      <dc:date>2015-04-24T06:46:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass field values as macro arguments?</title>
      <link>https://community.splunk.com/t5/Knowledge-Management/How-to-pass-field-values-as-macro-arguments/m-p/164023#M1575</link>
      <description>&lt;P&gt;Mason - I'm trying to replicate your code so that I can pass a field into a macro instead of a string, something that I really need to do to get around an data import issue that I have no immediate control over. &lt;/P&gt;

&lt;P&gt;I'm using the same syntax you had suggested, &lt;CODE&gt;newmacro(field3)&lt;/CODE&gt;. However, The &lt;EM&gt;name&lt;/EM&gt; of the field is getting passed into the macro as a string instead the &lt;EM&gt;value&lt;/EM&gt; of the field. I do not have quotes around the field. &lt;/P&gt;

&lt;P&gt;Got any suggestions?&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jan 2017 18:34:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Knowledge-Management/How-to-pass-field-values-as-macro-arguments/m-p/164023#M1575</guid>
      <dc:creator>wbcem</dc:creator>
      <dc:date>2017-01-17T18:34:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass field values as macro arguments?</title>
      <link>https://community.splunk.com/t5/Knowledge-Management/How-to-pass-field-values-as-macro-arguments/m-p/164024#M1576</link>
      <description>&lt;P&gt;I am trying to figure out the same issue as well...&lt;/P&gt;</description>
      <pubDate>Mon, 23 Mar 2020 21:20:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Knowledge-Management/How-to-pass-field-values-as-macro-arguments/m-p/164024#M1576</guid>
      <dc:creator>bwlm</dc:creator>
      <dc:date>2020-03-23T21:20:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to pass field values as macro arguments?</title>
      <link>https://community.splunk.com/t5/Knowledge-Management/How-to-pass-field-values-as-macro-arguments/m-p/678919#M9899</link>
      <description>&lt;P&gt;I am browsing to look for a solution to this issue and eventually accidentally found a solution myself. Try if this will work for you.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;PRE&gt;search sourcetype=type1 field1='$arg1$' | rename field2 as query | fields query | eval newField=query&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Single quotes will return the value of the field in an eval expression.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Feb 2024 05:02:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Knowledge-Management/How-to-pass-field-values-as-macro-arguments/m-p/678919#M9899</guid>
      <dc:creator>darljedmatundan</dc:creator>
      <dc:date>2024-02-28T05:02:27Z</dc:date>
    </item>
  </channel>
</rss>

