<?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: Javascript - Web framework - how to pass a parameter to the on method (&amp;quot;click:row&amp;quot;) in Dashboards &amp; Visualizations</title>
    <link>https://community.splunk.com/t5/Dashboards-Visualizations/Javascript-Web-framework-how-to-pass-a-parameter-to-the-on/m-p/337579#M21914</link>
    <description>&lt;P&gt;@OL, First off, have you verified whether you are working with default token model or submitted? Do you have &lt;CODE&gt;searchWhenChanged&lt;/CODE&gt; turned to &lt;CODE&gt;false&lt;/CODE&gt; and &lt;CODE&gt;submitButton&lt;/CODE&gt; set to &lt;CODE&gt;true&lt;/CODE&gt;? If you indeed have these then ideally you should not get &lt;CODE&gt;undefined&lt;/CODE&gt;. If you are coding click event handler for table view, Submitted token model will give you previously submitted value even though the value has changed.&lt;/P&gt;

&lt;P&gt;You can also try the following search if you are seeing undefined error in JavaScript:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;     var submittedTokenModel = mvc.Components.get("submitted");
     submittedTokenModel.on("change", function(e) {
         if(submittedTokenModel!==undefined){
             console.log("submittedTokenModel defined and changed: " + JSON.stringify(submittedTokenModel));
         }else{
             console.log("submittedTokenModel undefined");
         }
     });
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If it is for specific token change for defaultTokenModel, for example &lt;CODE&gt;&amp;lt;yourTokenName&amp;gt;&lt;/CODE&gt; you can add the following condition &lt;CODE&gt;if(&amp;lt;yourTokenName&amp;gt;!==undefined){ ...}&lt;/CODE&gt;. Replace &lt;CODE&gt;&amp;lt;yourTokenName&amp;gt;&lt;/CODE&gt; with the token name which you want to capture when it changes.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  var defaultTokenModel = mvc.Components.get("default");
 defaultTokenModel.on("change:&amp;lt;yourTokenName&amp;gt;", function(newTokenName, &amp;lt;yourTokenName&amp;gt;, options) 
 {
     if(&amp;lt;yourTokenName&amp;gt;!==undefined){
         console.log("&amp;lt;yourTokenName&amp;gt;: ",&amp;lt;yourTokenName&amp;gt;);
     }
 });
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 12 Mar 2018 15:36:17 GMT</pubDate>
    <dc:creator>niketn</dc:creator>
    <dc:date>2018-03-12T15:36:17Z</dc:date>
    <item>
      <title>Javascript - Web framework - how to pass a parameter to the on method ("click:row")</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Javascript-Web-framework-how-to-pass-a-parameter-to-the-on/m-p/337574#M21909</link>
      <description>&lt;P&gt;Hello, would anyone know if there is a way to pass a parameter to the on method in javascript?&lt;BR /&gt;
I have tried:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;var submittedTokenModel = mvc.Components.get("submitted");
console.log(submittedTokenModel);

table_view_obj.on("click:row", function(e, submittedTokenModel){
   console.log(submittedTokenModel);
});
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But the return submittedTokenModel objects in the console are different (and the second one is not what I want)&lt;/P&gt;</description>
      <pubDate>Fri, 09 Mar 2018 15:55:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Javascript-Web-framework-how-to-pass-a-parameter-to-the-on/m-p/337574#M21909</guid>
      <dc:creator>OL</dc:creator>
      <dc:date>2018-03-09T15:55:11Z</dc:date>
    </item>
    <item>
      <title>Re: Javascript - Web framework - how to pass a parameter to the on method ("click:row")</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Javascript-Web-framework-how-to-pass-a-parameter-to-the-on/m-p/337575#M21910</link>
      <description>&lt;P&gt;Hi @QL,&lt;BR /&gt;
Can you please share more information regarding what you want to pass on click?? Have you tried by removing &lt;CODE&gt;submittedTokenModel&lt;/CODE&gt; a a parameter ? Can you please try below?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;var submittedTokenModel = mvc.Components.get("submitted");
 console.log(submittedTokenModel);

 table_view_obj.on("click:row", function(e){
    console.log(submittedTokenModel);
 });
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 10 Mar 2018 08:13:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Javascript-Web-framework-how-to-pass-a-parameter-to-the-on/m-p/337575#M21910</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2018-03-10T08:13:54Z</dc:date>
    </item>
    <item>
      <title>Re: Javascript - Web framework - how to pass a parameter to the on method ("click:row")</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Javascript-Web-framework-how-to-pass-a-parameter-to-the-on/m-p/337576#M21911</link>
      <description>&lt;P&gt;You don't need to pass &lt;CODE&gt;submittedTokenModel&lt;/CODE&gt;, you can just do&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;var submittedTokenModel = mvc.Components.get("submitted");
table_view_obj.on("click:row", function(e){
    console.log(submittedTokenModel);
});
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Your browsers js engine will try to find &lt;CODE&gt;submittedTokenModel&lt;/CODE&gt; inside the local scope of the anonymous function. Since this function doesn't declare an object by that name, the engine will try to find it in the outer scope of the anonymous function, which in this case is the scope in which you declared both the anonymous function you assign to the click event of &lt;CODE&gt;table_view_obj&lt;/CODE&gt; and &lt;CODE&gt;submittedTokenModel&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;If the values of &lt;CODE&gt;submittedTokenModel&lt;/CODE&gt; are different between the initial console.log at the beginning of your code and when the event handler calls your anonymous function, then the token model has probably been changed by something. If you want to get notified whenever that happens, have something like this in your code:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;submittedTokenModel.on("change", function(e) {
    console.log("submittedTokenModel changed: " + JSON.stringify(submittedTokenModel));
});
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 12 Mar 2018 13:33:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Javascript-Web-framework-how-to-pass-a-parameter-to-the-on/m-p/337576#M21911</guid>
      <dc:creator>jeffland</dc:creator>
      <dc:date>2018-03-12T13:33:36Z</dc:date>
    </item>
    <item>
      <title>Re: Javascript - Web framework - how to pass a parameter to the on method ("click:row")</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Javascript-Web-framework-how-to-pass-a-parameter-to-the-on/m-p/337577#M21912</link>
      <description>&lt;P&gt;Hi Kamlesh_vaghela,&lt;BR /&gt;
Thank you for your reply. I wasn't to keep the question generic as other people might have different need, but to be more specific about my case, here is the workflow:&lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;A user click on a row, which correspond to the line he/she wants to delete&lt;/LI&gt;
&lt;LI&gt;a modal pop-up window appear asking if the user is sure he/she wants to delete the line&lt;/LI&gt;
&lt;LI&gt;if confirmed, it runs the search that delete the corresponding line.&lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;The dashboard is a but more complex and that is why I wanted to pass various parameters via the submittedTokenModel.&lt;/P&gt;

&lt;P&gt;And I tried what you mentioned, and I get a undef object in the function. It seems to work well with the defaultTokenModel.&lt;/P&gt;</description>
      <pubDate>Mon, 12 Mar 2018 14:37:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Javascript-Web-framework-how-to-pass-a-parameter-to-the-on/m-p/337577#M21912</guid>
      <dc:creator>OL</dc:creator>
      <dc:date>2018-03-12T14:37:51Z</dc:date>
    </item>
    <item>
      <title>Re: Javascript - Web framework - how to pass a parameter to the on method ("click:row")</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Javascript-Web-framework-how-to-pass-a-parameter-to-the-on/m-p/337578#M21913</link>
      <description>&lt;P&gt;Hi @jeffland,&lt;BR /&gt;
Thank you  very much for your help on this. This is what I originally tried by I had a undef object when I was in the function.&lt;/P&gt;</description>
      <pubDate>Mon, 12 Mar 2018 14:41:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Javascript-Web-framework-how-to-pass-a-parameter-to-the-on/m-p/337578#M21913</guid>
      <dc:creator>OL</dc:creator>
      <dc:date>2018-03-12T14:41:06Z</dc:date>
    </item>
    <item>
      <title>Re: Javascript - Web framework - how to pass a parameter to the on method ("click:row")</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Javascript-Web-framework-how-to-pass-a-parameter-to-the-on/m-p/337579#M21914</link>
      <description>&lt;P&gt;@OL, First off, have you verified whether you are working with default token model or submitted? Do you have &lt;CODE&gt;searchWhenChanged&lt;/CODE&gt; turned to &lt;CODE&gt;false&lt;/CODE&gt; and &lt;CODE&gt;submitButton&lt;/CODE&gt; set to &lt;CODE&gt;true&lt;/CODE&gt;? If you indeed have these then ideally you should not get &lt;CODE&gt;undefined&lt;/CODE&gt;. If you are coding click event handler for table view, Submitted token model will give you previously submitted value even though the value has changed.&lt;/P&gt;

&lt;P&gt;You can also try the following search if you are seeing undefined error in JavaScript:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;     var submittedTokenModel = mvc.Components.get("submitted");
     submittedTokenModel.on("change", function(e) {
         if(submittedTokenModel!==undefined){
             console.log("submittedTokenModel defined and changed: " + JSON.stringify(submittedTokenModel));
         }else{
             console.log("submittedTokenModel undefined");
         }
     });
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If it is for specific token change for defaultTokenModel, for example &lt;CODE&gt;&amp;lt;yourTokenName&amp;gt;&lt;/CODE&gt; you can add the following condition &lt;CODE&gt;if(&amp;lt;yourTokenName&amp;gt;!==undefined){ ...}&lt;/CODE&gt;. Replace &lt;CODE&gt;&amp;lt;yourTokenName&amp;gt;&lt;/CODE&gt; with the token name which you want to capture when it changes.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  var defaultTokenModel = mvc.Components.get("default");
 defaultTokenModel.on("change:&amp;lt;yourTokenName&amp;gt;", function(newTokenName, &amp;lt;yourTokenName&amp;gt;, options) 
 {
     if(&amp;lt;yourTokenName&amp;gt;!==undefined){
         console.log("&amp;lt;yourTokenName&amp;gt;: ",&amp;lt;yourTokenName&amp;gt;);
     }
 });
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 12 Mar 2018 15:36:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Javascript-Web-framework-how-to-pass-a-parameter-to-the-on/m-p/337579#M21914</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2018-03-12T15:36:17Z</dc:date>
    </item>
    <item>
      <title>Re: Javascript - Web framework - how to pass a parameter to the on method ("click:row")</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Javascript-Web-framework-how-to-pass-a-parameter-to-the-on/m-p/337580#M21915</link>
      <description>&lt;P&gt;Hi @niketnilay,&lt;/P&gt;

&lt;P&gt;I don't think the problem is with submittedTokenModel itself as when you use the console.log outside of the function, everything is working as expected. It is just when you call it from inside the function.&lt;/P&gt;</description>
      <pubDate>Mon, 12 Mar 2018 15:41:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Javascript-Web-framework-how-to-pass-a-parameter-to-the-on/m-p/337580#M21915</guid>
      <dc:creator>OL</dc:creator>
      <dc:date>2018-03-12T15:41:52Z</dc:date>
    </item>
    <item>
      <title>Re: Javascript - Web framework - how to pass a parameter to the on method ("click:row")</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Javascript-Web-framework-how-to-pass-a-parameter-to-the-on/m-p/337581#M21916</link>
      <description>&lt;P&gt;Can you share your current code? Or create a mock dashboard to recreate your issue?&lt;/P&gt;</description>
      <pubDate>Mon, 12 Mar 2018 15:48:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Javascript-Web-framework-how-to-pass-a-parameter-to-the-on/m-p/337581#M21916</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2018-03-12T15:48:21Z</dc:date>
    </item>
  </channel>
</rss>

