<?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: Is it possible to have optional arguments in search macros? in Knowledge Management</title>
    <link>https://community.splunk.com/t5/Knowledge-Management/Is-it-possible-to-have-optional-arguments-in-search-macros/m-p/168628#M1593</link>
    <description>&lt;P&gt;I usually do what I do with overloaded functions: Define one know-it-all version with n arguments, and feeder versions with lower-than-n arguments. Simple example:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;`my_top(1)` --&amp;gt; `my_top($field$, 20)`
`my_top(2)` --&amp;gt; stats count by $field$ | sort - count | head $num$
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The user of the macro can choose to define the optional &lt;CODE&gt;num&lt;/CODE&gt; argument or not, then he gets the default of 20. For this example zero arguments would only make sense if you could reasonably guess a default field name to count by.&lt;/P&gt;</description>
    <pubDate>Wed, 29 Apr 2015 15:28:20 GMT</pubDate>
    <dc:creator>martin_mueller</dc:creator>
    <dc:date>2015-04-29T15:28:20Z</dc:date>
    <item>
      <title>Is it possible to have optional arguments in search macros?</title>
      <link>https://community.splunk.com/t5/Knowledge-Management/Is-it-possible-to-have-optional-arguments-in-search-macros/m-p/168627#M1592</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;I'm reading about search macros, and I was wondering if there was a way to have optional arguments? From what I've read, the definitions of arguments is an absolute number ( e.g. foo(#) ). The most obvious solution would be to make a macro with the same name with 1, 2, 3, 4, etc arguments for the expected combinations of optional arguments.&lt;/P&gt;

&lt;P&gt;Maybe defining the number of arguments to be an impossibly large number and formulate the search such that it works with null fields?&lt;/P&gt;

&lt;P&gt;I don't have a concrete example, but something that comes to mind could be a complex or bulky search that could take any number of fields.  Just trying to figure out what I can and can't do with macros.&lt;/P&gt;

&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 29 Apr 2015 14:08:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Knowledge-Management/Is-it-possible-to-have-optional-arguments-in-search-macros/m-p/168627#M1592</guid>
      <dc:creator>j4adam</dc:creator>
      <dc:date>2015-04-29T14:08:30Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to have optional arguments in search macros?</title>
      <link>https://community.splunk.com/t5/Knowledge-Management/Is-it-possible-to-have-optional-arguments-in-search-macros/m-p/168628#M1593</link>
      <description>&lt;P&gt;I usually do what I do with overloaded functions: Define one know-it-all version with n arguments, and feeder versions with lower-than-n arguments. Simple example:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;`my_top(1)` --&amp;gt; `my_top($field$, 20)`
`my_top(2)` --&amp;gt; stats count by $field$ | sort - count | head $num$
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The user of the macro can choose to define the optional &lt;CODE&gt;num&lt;/CODE&gt; argument or not, then he gets the default of 20. For this example zero arguments would only make sense if you could reasonably guess a default field name to count by.&lt;/P&gt;</description>
      <pubDate>Wed, 29 Apr 2015 15:28:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Knowledge-Management/Is-it-possible-to-have-optional-arguments-in-search-macros/m-p/168628#M1593</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2015-04-29T15:28:20Z</dc:date>
    </item>
  </channel>
</rss>

