<?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 use external variables in search command? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-external-variables-in-search-command/m-p/69284#M17377</link>
    <description>&lt;P&gt;I added more code samples to walk you through it, and I also fixed an embarassing typo in the customBehavior javascript. Sorry about that.&lt;/P&gt;</description>
    <pubDate>Tue, 25 Sep 2012 05:02:16 GMT</pubDate>
    <dc:creator>sideview</dc:creator>
    <dc:date>2012-09-25T05:02:16Z</dc:date>
    <item>
      <title>How to use external variables in search command?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-external-variables-in-search-command/m-p/69281#M17374</link>
      <description>&lt;P&gt;application.js&lt;BR /&gt;
 value = Splunk.util.getParameter("name");&lt;BR /&gt;
 localStorage.setItem("name",value);&lt;/P&gt;

&lt;P&gt;I saved parameter value by using html5 localStorage.(similar session value control)&lt;/P&gt;

&lt;P&gt;in application.js file, I can get name value -&amp;gt; localStorage.getItem("name")&lt;/P&gt;

&lt;P&gt;in this case, I want use this value to splunk advancedXML search variable.&lt;/P&gt;

&lt;P&gt;How can I do??&lt;/P&gt;</description>
      <pubDate>Tue, 25 Sep 2012 00:32:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-external-variables-in-search-command/m-p/69281#M17374</guid>
      <dc:creator>kjycls</dc:creator>
      <dc:date>2012-09-25T00:32:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to use external variables in search command?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-external-variables-in-search-command/m-p/69282#M17375</link>
      <description>&lt;P&gt;You could use a NullModule and then write a tricky patch from application.js,  or you could make life a bit easier and use Sideview Utils and its "CustomBehavior" module. &lt;/P&gt;

&lt;P&gt;Step 1) download Sideview Utils 2.1.X from &lt;A href="http://sideviewapps.com/apps/sideview-utils"&gt;http://sideviewapps.com/apps/sideview-utils&lt;/A&gt; &lt;/P&gt;

&lt;P&gt;Step 2) put the SideviewUtils module on your view. Put it at the top next to AccountBar and AppBar.  It's invisible and it'll be out of the way up there. &lt;BR /&gt;
ie:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;module name="AccountBar" layoutPanel="appHeader" /&amp;gt;
&amp;lt;module name="AppBar" layoutPanel="appHeader" /&amp;gt;
&amp;lt;module name="SideviewUtils" layoutPanel="appHeader" /&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Step 3) Put a CustomBehavior module into the page, at a point in the Advanced XML downstream from which you want the value to be available.  Given it a "customBehavior" param of "getNameFromLocalStorage"&lt;/P&gt;

&lt;P&gt;ie:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;module name="CustomBehavior"&amp;gt;
  &amp;lt;param name="customBehavior"&amp;gt;getNameFromLocalStorage&amp;lt;/param&amp;gt;

  &amp;lt;module name="HTML"&amp;gt;
    &amp;lt;param name="html"&amp;gt;&amp;lt;![CDATA[
      The name from localStorage is $name$
    ]]&amp;gt;&amp;lt;/param&amp;gt;
  &amp;lt;/module&amp;gt;      
&amp;lt;/module&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Step 4) in application.js,  you define the customBehavior like so. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Sideview.utils.declareCustomBehavior("getNameFromLocalStorage", function(customBehaviorModule) {
    customBehaviorModule.getModifiedContext = function() {
        var context = this.getContext();
        context.set("name", localStorage.getItem("name"));
        return context;
    }
});
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Step 5) downstream from the CustomBehavior module you can use the Sideview Search module or HTML module to reference $name$,  and at runtime it will be the value from localStorage. (See the example I listed in Step 3, above)&lt;/P&gt;

&lt;P&gt;If you want to use the trickier way with the NullModule patch, it's not &lt;EM&gt;that&lt;/EM&gt; bad in this case, and I can spell that out for you too..&lt;/P&gt;</description>
      <pubDate>Tue, 25 Sep 2012 02:39:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-external-variables-in-search-command/m-p/69282#M17375</guid>
      <dc:creator>sideview</dc:creator>
      <dc:date>2012-09-25T02:39:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to use external variables in search command?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-external-variables-in-search-command/m-p/69283#M17376</link>
      <description>&lt;P&gt;Thank you~ Can I know Stop3 syntax?&lt;/P&gt;</description>
      <pubDate>Tue, 25 Sep 2012 04:35:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-external-variables-in-search-command/m-p/69283#M17376</guid>
      <dc:creator>kjycls</dc:creator>
      <dc:date>2012-09-25T04:35:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to use external variables in search command?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-external-variables-in-search-command/m-p/69284#M17377</link>
      <description>&lt;P&gt;I added more code samples to walk you through it, and I also fixed an embarassing typo in the customBehavior javascript. Sorry about that.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Sep 2012 05:02:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-external-variables-in-search-command/m-p/69284#M17377</guid>
      <dc:creator>sideview</dc:creator>
      <dc:date>2012-09-25T05:02:16Z</dc:date>
    </item>
  </channel>
</rss>

