<?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: Failed to execute button | ModalView | javascript | Why is popup.js file unable to see selected_values_array variabl in Dashboards &amp; Visualizations</title>
    <link>https://community.splunk.com/t5/Dashboards-Visualizations/Failed-to-execute-button-ModalView-javascript-Why-is-popup-js/m-p/610993#M50089</link>
    <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/244586"&gt;@crteixeira&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have made some changes to your JS. Please try it and let me know if any issues.&lt;/P&gt;&lt;P&gt;popup.js&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;define([
  'underscore',
  'backbone',
  'jquery',
  'splunkjs/mvc',
  'splunkjs/mvc/searchmanager',
  'splunkjs/mvc/simplexml/element/table',
  ], function(_, Backbone, $, mvc, SearchManager, TableElement) {

      var modalTemplate = "&amp;lt;div id=\"pivotModal\" class=\"modal\"&amp;gt;" +
                     "&amp;lt;div class=\"modal-header\"&amp;gt;&amp;lt;h3&amp;gt;&amp;lt;%- title %&amp;gt;&amp;lt;/h3&amp;gt;&amp;lt;button class=\"close\"&amp;gt;Close&amp;lt;/button&amp;gt;&amp;lt;/div&amp;gt;" +
                     "&amp;lt;div class=\"modal-body\"&amp;gt;&amp;lt;/div&amp;gt;" +
                     "&amp;lt;div class=\"modal-footer\"&amp;gt;&amp;lt;button type=\"button\" id=\"teste\" class=\"confirm\"&amp;gt;Confirmar&amp;lt;/button&amp;gt;&amp;lt;/div&amp;gt;" +
                     "&amp;lt;/div&amp;gt;" +
                     "&amp;lt;div class=\"modal-backdrop\"&amp;gt;&amp;lt;/div&amp;gt;";

      var ModalView = Backbone.View.extend({

          defaults: {
                 title: 'Not set'
          },

          initialize: function(options) {
              this.options = options;
              this.options = _.extend({}, this.defaults, this.options);
              this.childViews = [];
              console.log('Hello from the modal window: ', this.options.title);
              this.template = _.template(modalTemplate);
          },

          events: {
                 'click .close': 'close',
             'click .modal-backdrop': 'close',
             'click .confirm': 'confirm',
          },

          render: function() {
              var data = { title : this.options.title };
                  this.$el.html(this.template(data));
              return this;
          },

          show: function() {
                  $(document.body).append(this.render().el);

              $(this.el).find('.modal-body').append('&amp;lt;div id="modalVizualization"/&amp;gt;');

              $(this.el).find('.modal').css({
                  width:'90%',
                  height:'auto',
                  left: '5%',
                  'margin-left': '0',
                  'max-height':'100%'
              });

              var search = mvc.Components.get(this.options.search.id);

              var detailTable = new TableElement({
                      id: "detailTable",
                      managerid: search.name,
                      pageSize: "5",
                      el: $('#modalVizualization')
              }).render();

              this.childViews.push(detailTable);
              search.startSearch();
          },

          close: function() {
                 this.unbind();
             this.remove();
             _.each(this.childViews, function(childView) {

                 childView.unbind();
                 childView.remove();

             });
          },

          confirm: function() {
                console.log(this.options.selected_values_array);
              // tokens.seCredit t("mytoken", selected_values_array.join());
              // submittedTokens.set(tokens.toJSON());
              new SearchManager({
                  id: "envSearch",
                  // earliest_time: "$time$",
                  // latest_time: "$time$",
                  preview: true,
                  cache: false,
                  search: "| makeresults | eval myvalue=\""+this.options.selected_values_array+"\" | makemv delim=\",\" myvalue | rename myvalue as URL | stats count by URL | table URL | outputlookup append=t dev-tk"
              });
          }
      });

      return ModalView;
  });&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;checkbox.js&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;require([
  'underscore',
  'jquery',
  'backbone',
  '../app/search/crteixeira_popup',
  'splunkjs/mvc',
  'splunkjs/mvc/tableview',
  'splunkjs/mvc/searchmanager',
  'splunkjs/mvc/simplexml/ready!'
], function (_, $, Backbone, ModalView, mvc, TableView, SearchManager) {
  // Access the "default" token model
  var tokens = mvc.Components.get("default");
  var selected_values_array = [];
  var submittedTokens = mvc.Components.get('submitted');


  var CustomRangeRenderer = TableView.BaseCellRenderer.extend({
      canRender: function (cell) {
          return _(['teste']).contains(cell.field);
      },
      render: function ($td, cell) {
          var a = $('&amp;lt;div&amp;gt;').attr({ "id": "chk-URL" + cell.value, "value": cell.value }).addClass('checkbox').click(function () {
              // console.log("checked",$(this).attr('class'));
              // console.log("checked",$(this).attr('value'));
              if ($(this).attr('class') === "checkbox") {
                  selected_values_array.push($(this).attr('value'));
                  $(this).removeClass();
                  $(this).addClass("checkbox checked");
              }
              else {
                  $(this).removeClass();
                  $(this).addClass("checkbox");
                  var i = selected_values_array.indexOf($(this).attr('value'));
                  if (i != -1) {
                      selected_values_array.splice(i, 1);
                  }
                  // Change the value of a token $mytoken$
              }
              console.log(selected_values_array);
          }).appendTo($td);
          console.log(selected_values_array);
      }
  });

  var detailSearch = new SearchManager({
      id: "detailSearch",
      earliest_time: "$time$",
      latest_time: "$time$",
      preview: true,
      cache: false,
      search: "| makeresults | eval myvalue=\"$mytoken$\" | makemv delim=\",\" myvalue | stats count by myvalue | table myvalue"
  }, { tokens: true, tokenNamespace: "submitted" });

  //List of table IDs
  var tableIDs = ["myTable"];
  for (i = 0; i &amp;lt; tableIDs.length; i++) {
      var sh = mvc.Components.get(tableIDs[i]);
      if (typeof (sh) != "undefined") {
          sh.getVisualization(function (tableView) {
              // Add custom cell renderer and force re-render
              tableView.table.addCellRenderer(new CustomRangeRenderer());
              tableView.table.render();
          });
      }
  };

  $(document).ready(function () {
      $("#mybutton").on("click", function (e) {
          e.preventDefault();
          tokens.set("mytoken", selected_values_array.join());
          submittedTokens.set(tokens.toJSON());
          var modal = new ModalView({ title: "ModalView Window", search: detailSearch, selected_values_array:selected_values_array });
          modal.show();
          console.log(tokens);
          console.log(selected_values_array  + " selected_values_array");
          console.log(modal  + " modal");
          //console.log(render);
      });
  });
});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope this will help you.&lt;/P&gt;&lt;P&gt;Thanks&lt;BR /&gt;KV&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;If any of my replies help you to solve the problem Or gain knowledge, an upvote would be appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 26 Aug 2022 17:15:55 GMT</pubDate>
    <dc:creator>kamlesh_vaghela</dc:creator>
    <dc:date>2022-08-26T17:15:55Z</dc:date>
    <item>
      <title>Failed to execute button | ModalView | javascript | Why is popup.js file unable to see selected_values_array variable?</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Failed-to-execute-button-ModalView-javascript-Why-is-popup-js/m-p/609748#M49998</link>
      <description>&lt;P&gt;Hey guys, good night, how are you?&lt;/P&gt;
&lt;P&gt;I have a big problem&lt;/P&gt;
&lt;P&gt;I created an app with the integration of a checkbox with ModalView&lt;/P&gt;
&lt;P&gt;I need to send the data shown in the modal to a lookup, but the popup.js file is unable to see the selected_values_array variable from the checkbox.js file&lt;/P&gt;
&lt;P&gt;Have you ever been through this? Can you help me?&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;DIV&gt;
&lt;DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;checkbox.js&lt;/STRONG&gt;&lt;/P&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;require([
    'underscore',
    'jquery',
    'backbone',
    '../app/meuapp/popup',
    'splunkjs/mvc',
    'splunkjs/mvc/tableview',
    'splunkjs/mvc/searchmanager',
    'splunkjs/mvc/simplexml/ready!'
], function (_, $, Backbone, ModalView, mvc, TableView, SearchManager) {
    // Access the "default" token model
    var tokens = mvc.Components.get("default");
    var selected_values_array = [];
    var submittedTokens = mvc.Components.get('submitted');


    var CustomRangeRenderer = TableView.BaseCellRenderer.extend({
        canRender: function (cell) {
            return _(['teste']).contains(cell.field);
        },
        render: function ($td, cell) {
            var a = $('&amp;lt;div&amp;gt;').attr({ "id": "chk-URL" + cell.value, "value": cell.value }).addClass('checkbox').click(function () {
                // console.log("checked",$(this).attr('class'));
                // console.log("checked",$(this).attr('value'));
                if ($(this).attr('class') === "checkbox") {
                    selected_values_array.push($(this).attr('value'));
                    $(this).removeClass();
                    $(this).addClass("checkbox checked");
                }
                else {
                    $(this).removeClass();
                    $(this).addClass("checkbox");
                    var i = selected_values_array.indexOf($(this).attr('value'));
                    if (i != -1) {
                        selected_values_array.splice(i, 1);
                    }
                    // Change the value of a token $mytoken$
                }
                console.log(selected_values_array);
            }).appendTo($td);
            console.log(selected_values_array);
        }
    });

    var detailSearch = new SearchManager({
        id: "detailSearch",
        earliest_time: "$time$",
        latest_time: "$time$",
        preview: true,
        cache: false,
        search: "| makeresults | eval myvalue=\"$mytoken$\" | makemv delim=\",\" myvalue | stats count by myvalue | table myvalue"
    }, { tokens: true, tokenNamespace: "submitted" });
 
    //List of table IDs
    var tableIDs = ["myTable"];
    for (i = 0; i &amp;lt; tableIDs.length; i++) {
        var sh = mvc.Components.get(tableIDs[i]);
        if (typeof (sh) != "undefined") {
            sh.getVisualization(function (tableView) {
                // Add custom cell renderer and force re-render
                tableView.table.addCellRenderer(new CustomRangeRenderer());
                tableView.table.render();
            });
        }
    };

    $(document).ready(function () {
        $("#mybutton").on("click", function (e) {
            e.preventDefault();
            tokens.set("mytoken", selected_values_array.join());
            submittedTokens.set(tokens.toJSON());
            var modal = new ModalView({ title: "ModalView Window", search: detailSearch });
            modal.show();
            console.log(tokens);
            console.log(selected_values_array  + " selected_values_array");
            console.log(modal  + " modal");
            //console.log(render);
        });
    });
});&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;popup.js&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;define([
    'underscore',
    'backbone',
    'jquery',
    'splunkjs/mvc',
    'splunkjs/mvc/searchmanager',
    'splunkjs/mvc/simplexml/element/table',
    ], function(_, Backbone, $, mvc, SearchManager, TableElement) {

        var modalTemplate = "&amp;lt;div id=\"pivotModal\" class=\"modal\"&amp;gt;" +
                       "&amp;lt;div class=\"modal-header\"&amp;gt;&amp;lt;h3&amp;gt;&amp;lt;%- title %&amp;gt;&amp;lt;/h3&amp;gt;&amp;lt;button class=\"close\"&amp;gt;Close&amp;lt;/button&amp;gt;&amp;lt;/div&amp;gt;" +
                       "&amp;lt;div class=\"modal-body\"&amp;gt;&amp;lt;/div&amp;gt;" +
                       "&amp;lt;div class=\"modal-footer\"&amp;gt;&amp;lt;button type=\"button\" id=\"teste\" class=\"confirm\"&amp;gt;Confirmar&amp;lt;/button&amp;gt;&amp;lt;/div&amp;gt;" +
                       "&amp;lt;/div&amp;gt;" +
                       "&amp;lt;div class=\"modal-backdrop\"&amp;gt;&amp;lt;/div&amp;gt;";

        var ModalView = Backbone.View.extend({

            defaults: {
                   title: 'Not set'
            },

            initialize: function(options) {
                this.options = options;
                this.options = _.extend({}, this.defaults, this.options);
                this.childViews = [];
                console.log('Hello from the modal window: ', this.options.title);
                this.template = _.template(modalTemplate);
            },

            events: {
                   'click .close': 'close',
               'click .modal-backdrop': 'close',
               'click .confirm': 'confirm',
            },

            render: function() {
                var data = { title : this.options.title };
                    this.$el.html(this.template(data));
                return this;
            },

            show: function() {
                    $(document.body).append(this.render().el);

                $(this.el).find('.modal-body').append('&amp;lt;div id="modalVizualization"/&amp;gt;');

                $(this.el).find('.modal').css({
                    width:'90%',
                    height:'auto',
                    left: '5%',
                    'margin-left': '0',
                    'max-height':'100%'
                });

                var search = mvc.Components.get(this.options.search.id);

                var detailTable = new TableElement({
                        id: "detailTable",
                        managerid: search.name,
                        pageSize: "5",
                        el: $('#modalVizualization')
                }).render();

                this.childViews.push(detailTable);
                search.startSearch();
            },

            close: function() {
                   this.unbind();
               this.remove();
               _.each(this.childViews, function(childView) {

                   childView.unbind();
                   childView.remove();

               });
            },

            confirm: function(selected_values_array) {
                tokens.set("mytoken", selected_values_array.join());
                submittedTokens.set(tokens.toJSON());
                new SearchManager({
                    id: "envSearch",
                    earliest_time: "$time$",
                    latest_time: "$time$",
                    preview: true,
                    cache: false,
                    search: "| makeresults | eval myvalue=\"$mytoken$\" | makemv delim=\",\" myvalue | rename myvalue as URL | stats count by URL | table URL | outputlookup append=t dev-tk"
                });
            }
        });

        return ModalView;
    });&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;chexkbox.css&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="css"&gt;/* The standalone checkbox square*/
.checkbox {
  width:20px;
  height:20px;
  border: 1px solid #000;
  display: inline-block;
}

/* This is what simulates a checkmark icon */
.checkbox.checked:after {
  content: '';
  display: block;
  width: 4px;
  height: 7px;

  /* "Center" the checkmark */
  position:relative;
  top:4px;
  left:7px;

  border: solid #000;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;dash.xml&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;&amp;lt;dashboard script="checkbox.js" stylesheet="checkbox.css"&amp;gt;
&amp;lt;label&amp;gt;Teste &amp;lt;/label&amp;gt;
&amp;lt;row&amp;gt;
&amp;lt;panel&amp;gt;
&amp;lt;table id="myTable"&amp;gt;
&amp;lt;title&amp;gt;My Table&amp;lt;/title&amp;gt;
&amp;lt;search&amp;gt;
&amp;lt;query&amp;gt;index=_internal | stats count by sourcetype | eval teste=sourcetype&amp;lt;/query&amp;gt;
&amp;lt;earliest&amp;gt;-15m&amp;lt;/earliest&amp;gt;
&amp;lt;latest&amp;gt;now&amp;lt;/latest&amp;gt;
&amp;lt;/search&amp;gt;
&amp;lt;option name="count"&amp;gt;10&amp;lt;/option&amp;gt;
&amp;lt;option name="drilldown"&amp;gt;row&amp;lt;/option&amp;gt;
&amp;lt;option name="refresh.display"&amp;gt;progressbar&amp;lt;/option&amp;gt;
&amp;lt;drilldown&amp;gt;
&amp;lt;condition field="*"&amp;gt;&amp;lt;/condition&amp;gt;
&amp;lt;/drilldown&amp;gt;
&amp;lt;/table&amp;gt;
&amp;lt;/panel&amp;gt;
&amp;lt;/row&amp;gt;
&amp;lt;row&amp;gt;
&amp;lt;panel&amp;gt;
&amp;lt;html&amp;gt;
&amp;lt;div&amp;gt;
&amp;lt;input type="button" id="mybutton" value="My Button"/&amp;gt;
&amp;lt;/div&amp;gt;
&amp;lt;/html&amp;gt;
&amp;lt;/panel&amp;gt;
&amp;lt;/row&amp;gt;

&amp;lt;/dashboard&amp;gt;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="crteixeira_0-1660707041958.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/21062iFDAFFF9F3419B83A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="crteixeira_0-1660707041958.png" alt="crteixeira_0-1660707041958.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Aug 2022 14:33:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Failed-to-execute-button-ModalView-javascript-Why-is-popup-js/m-p/609748#M49998</guid>
      <dc:creator>crteixeira</dc:creator>
      <dc:date>2022-08-17T14:33:26Z</dc:date>
    </item>
    <item>
      <title>Re: Failed to execute button | ModalView | javascript | Why is popup.js file unable to see selected_values_array variabl</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Failed-to-execute-button-ModalView-javascript-Why-is-popup-js/m-p/610946#M50084</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/244586"&gt;@crteixeira&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your code looks good to me. Just one question. In the popup modal, there is a confirm button. What is the logic behind it?&lt;/P&gt;&lt;P&gt;I found some code mistakes where a few tokens are undefined. Like, `&lt;SPAN&gt;tokens` , `&lt;/SPAN&gt;&lt;SPAN&gt;submittedTokens`, `&lt;/SPAN&gt;&lt;SPAN&gt;time` .&amp;nbsp; Please elaborate the requirement so I can help you in this code as well.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;confirm: function(selected_values_array) {
                tokens.set("mytoken", selected_values_array.join());
                submittedTokens.set(tokens.toJSON());
                new SearchManager({
                    id: "envSearch",
                    earliest_time: "$time$",
                    latest_time: "$time$",
                    preview: true,
                    cache: false,
                    search: "| makeresults | eval myvalue=\"$mytoken$\" | makemv delim=\",\" myvalue | rename myvalue as URL | stats count by URL | table URL | outputlookup append=t dev-tk"
                });
            }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope this will help you.&lt;/P&gt;&lt;P&gt;Thanks&lt;BR /&gt;KV&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;If any of my reply helps you to solve the problem Or gain knowledge, an upvote would be appreciated.&lt;/P&gt;</description>
      <pubDate>Fri, 26 Aug 2022 11:50:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Failed-to-execute-button-ModalView-javascript-Why-is-popup-js/m-p/610946#M50084</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2022-08-26T11:50:26Z</dc:date>
    </item>
    <item>
      <title>Re: Failed to execute button | ModalView | javascript | Why is popup.js file unable to see selected_values_array variabl</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Failed-to-execute-button-ModalView-javascript-Why-is-popup-js/m-p/610967#M50088</link>
      <description>&lt;P&gt;The logic would be that the URLs marked on the panel appear in the popup if they were a preview&lt;/P&gt;&lt;P&gt;And when you click confirm you will be sent to a kvstore&lt;/P&gt;&lt;P&gt;The problem is that the popup.js file does not recognize the Token being worked on in the checkbox.js file so it does not accept the "join"&lt;/P&gt;&lt;P&gt;I understand that "mytoken" data is stored in "selected_values_array" so I tried calling it but it doesn't work&lt;/P&gt;</description>
      <pubDate>Fri, 26 Aug 2022 15:00:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Failed-to-execute-button-ModalView-javascript-Why-is-popup-js/m-p/610967#M50088</guid>
      <dc:creator>crteixeira</dc:creator>
      <dc:date>2022-08-26T15:00:06Z</dc:date>
    </item>
    <item>
      <title>Re: Failed to execute button | ModalView | javascript | Why is popup.js file unable to see selected_values_array variabl</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Failed-to-execute-button-ModalView-javascript-Why-is-popup-js/m-p/610993#M50089</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/244586"&gt;@crteixeira&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have made some changes to your JS. Please try it and let me know if any issues.&lt;/P&gt;&lt;P&gt;popup.js&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;define([
  'underscore',
  'backbone',
  'jquery',
  'splunkjs/mvc',
  'splunkjs/mvc/searchmanager',
  'splunkjs/mvc/simplexml/element/table',
  ], function(_, Backbone, $, mvc, SearchManager, TableElement) {

      var modalTemplate = "&amp;lt;div id=\"pivotModal\" class=\"modal\"&amp;gt;" +
                     "&amp;lt;div class=\"modal-header\"&amp;gt;&amp;lt;h3&amp;gt;&amp;lt;%- title %&amp;gt;&amp;lt;/h3&amp;gt;&amp;lt;button class=\"close\"&amp;gt;Close&amp;lt;/button&amp;gt;&amp;lt;/div&amp;gt;" +
                     "&amp;lt;div class=\"modal-body\"&amp;gt;&amp;lt;/div&amp;gt;" +
                     "&amp;lt;div class=\"modal-footer\"&amp;gt;&amp;lt;button type=\"button\" id=\"teste\" class=\"confirm\"&amp;gt;Confirmar&amp;lt;/button&amp;gt;&amp;lt;/div&amp;gt;" +
                     "&amp;lt;/div&amp;gt;" +
                     "&amp;lt;div class=\"modal-backdrop\"&amp;gt;&amp;lt;/div&amp;gt;";

      var ModalView = Backbone.View.extend({

          defaults: {
                 title: 'Not set'
          },

          initialize: function(options) {
              this.options = options;
              this.options = _.extend({}, this.defaults, this.options);
              this.childViews = [];
              console.log('Hello from the modal window: ', this.options.title);
              this.template = _.template(modalTemplate);
          },

          events: {
                 'click .close': 'close',
             'click .modal-backdrop': 'close',
             'click .confirm': 'confirm',
          },

          render: function() {
              var data = { title : this.options.title };
                  this.$el.html(this.template(data));
              return this;
          },

          show: function() {
                  $(document.body).append(this.render().el);

              $(this.el).find('.modal-body').append('&amp;lt;div id="modalVizualization"/&amp;gt;');

              $(this.el).find('.modal').css({
                  width:'90%',
                  height:'auto',
                  left: '5%',
                  'margin-left': '0',
                  'max-height':'100%'
              });

              var search = mvc.Components.get(this.options.search.id);

              var detailTable = new TableElement({
                      id: "detailTable",
                      managerid: search.name,
                      pageSize: "5",
                      el: $('#modalVizualization')
              }).render();

              this.childViews.push(detailTable);
              search.startSearch();
          },

          close: function() {
                 this.unbind();
             this.remove();
             _.each(this.childViews, function(childView) {

                 childView.unbind();
                 childView.remove();

             });
          },

          confirm: function() {
                console.log(this.options.selected_values_array);
              // tokens.seCredit t("mytoken", selected_values_array.join());
              // submittedTokens.set(tokens.toJSON());
              new SearchManager({
                  id: "envSearch",
                  // earliest_time: "$time$",
                  // latest_time: "$time$",
                  preview: true,
                  cache: false,
                  search: "| makeresults | eval myvalue=\""+this.options.selected_values_array+"\" | makemv delim=\",\" myvalue | rename myvalue as URL | stats count by URL | table URL | outputlookup append=t dev-tk"
              });
          }
      });

      return ModalView;
  });&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;checkbox.js&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;require([
  'underscore',
  'jquery',
  'backbone',
  '../app/search/crteixeira_popup',
  'splunkjs/mvc',
  'splunkjs/mvc/tableview',
  'splunkjs/mvc/searchmanager',
  'splunkjs/mvc/simplexml/ready!'
], function (_, $, Backbone, ModalView, mvc, TableView, SearchManager) {
  // Access the "default" token model
  var tokens = mvc.Components.get("default");
  var selected_values_array = [];
  var submittedTokens = mvc.Components.get('submitted');


  var CustomRangeRenderer = TableView.BaseCellRenderer.extend({
      canRender: function (cell) {
          return _(['teste']).contains(cell.field);
      },
      render: function ($td, cell) {
          var a = $('&amp;lt;div&amp;gt;').attr({ "id": "chk-URL" + cell.value, "value": cell.value }).addClass('checkbox').click(function () {
              // console.log("checked",$(this).attr('class'));
              // console.log("checked",$(this).attr('value'));
              if ($(this).attr('class') === "checkbox") {
                  selected_values_array.push($(this).attr('value'));
                  $(this).removeClass();
                  $(this).addClass("checkbox checked");
              }
              else {
                  $(this).removeClass();
                  $(this).addClass("checkbox");
                  var i = selected_values_array.indexOf($(this).attr('value'));
                  if (i != -1) {
                      selected_values_array.splice(i, 1);
                  }
                  // Change the value of a token $mytoken$
              }
              console.log(selected_values_array);
          }).appendTo($td);
          console.log(selected_values_array);
      }
  });

  var detailSearch = new SearchManager({
      id: "detailSearch",
      earliest_time: "$time$",
      latest_time: "$time$",
      preview: true,
      cache: false,
      search: "| makeresults | eval myvalue=\"$mytoken$\" | makemv delim=\",\" myvalue | stats count by myvalue | table myvalue"
  }, { tokens: true, tokenNamespace: "submitted" });

  //List of table IDs
  var tableIDs = ["myTable"];
  for (i = 0; i &amp;lt; tableIDs.length; i++) {
      var sh = mvc.Components.get(tableIDs[i]);
      if (typeof (sh) != "undefined") {
          sh.getVisualization(function (tableView) {
              // Add custom cell renderer and force re-render
              tableView.table.addCellRenderer(new CustomRangeRenderer());
              tableView.table.render();
          });
      }
  };

  $(document).ready(function () {
      $("#mybutton").on("click", function (e) {
          e.preventDefault();
          tokens.set("mytoken", selected_values_array.join());
          submittedTokens.set(tokens.toJSON());
          var modal = new ModalView({ title: "ModalView Window", search: detailSearch, selected_values_array:selected_values_array });
          modal.show();
          console.log(tokens);
          console.log(selected_values_array  + " selected_values_array");
          console.log(modal  + " modal");
          //console.log(render);
      });
  });
});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope this will help you.&lt;/P&gt;&lt;P&gt;Thanks&lt;BR /&gt;KV&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;If any of my replies help you to solve the problem Or gain knowledge, an upvote would be appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Aug 2022 17:15:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Failed-to-execute-button-ModalView-javascript-Why-is-popup-js/m-p/610993#M50089</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2022-08-26T17:15:55Z</dc:date>
    </item>
    <item>
      <title>Re: Failed to execute button | ModalView | javascript | Why is popup.js file unable to see selected_values_array variabl</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Failed-to-execute-button-ModalView-javascript-Why-is-popup-js/m-p/611035#M50093</link>
      <description>&lt;P&gt;Perfect &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/127939"&gt;@kamlesh_vaghela&lt;/a&gt;&amp;nbsp;!!!&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Thank you!!&lt;BR /&gt;I'm very happy, it worked perfectly&lt;/P&gt;&lt;P&gt;And even with your code I learned to import the variable, thank you very much&lt;/P&gt;&lt;P&gt;Now I'm going to proceed with the customizations, thank you&lt;/P&gt;</description>
      <pubDate>Sat, 27 Aug 2022 03:02:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Failed-to-execute-button-ModalView-javascript-Why-is-popup-js/m-p/611035#M50093</guid>
      <dc:creator>crteixeira</dc:creator>
      <dc:date>2022-08-27T03:02:11Z</dc:date>
    </item>
    <item>
      <title>Re: Failed to execute button | ModalView | javascript | Why is popup.js file unable to see selected_values_array variabl</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Failed-to-execute-button-ModalView-javascript-Why-is-popup-js/m-p/611056#M50094</link>
      <description>&lt;P&gt;Glad to help you&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/244586"&gt;@crteixeira&lt;/a&gt;&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;BR /&gt;KV&lt;BR /&gt;If any of my replies help you to solve the problem Or gain knowledge, an upvote would be appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 27 Aug 2022 14:56:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Failed-to-execute-button-ModalView-javascript-Why-is-popup-js/m-p/611056#M50094</guid>
      <dc:creator>kamlesh_vaghela</dc:creator>
      <dc:date>2022-08-27T14:56:43Z</dc:date>
    </item>
  </channel>
</rss>

