Dashboards & Visualizations
Highlighted

Why isn't JavaScript executing in my dashboard? I used a XML file.

Explorer

Hello,
I created a dashboard using this xml file :

`
FL ERRORS

<panel>
  <html>
    <h2>FL ERRS</h2>

    <p>Select a market:</p>
    <div id="marketlist"></div>&lt;br/&gt;

    <p>Here's the search:</p>
    <div id="text1"></div>
    <div id="tableindex"></div>
  </html>
</panel>

`
but, it doesn't execute the javascript file, and I have an empty dashboard.
Is something missing in my javascript ?

thanks,
Fausto


The javascript file is :

require([
    "splunkjs/mvc",
    "splunkjs/mvc/searchmanager",
    "splunkjs/mvc/dropdownview",
    "splunkjs/mvc/tableview",
    "splunkjs/mvc/textinputview",
    "splunkjs/mvc/simplexml/ready!"
], function(
    mvc,
    SearchManager,
    DropdownView,
    TableView,
    TextInputView
) {

    // Search query is based on the selected index
    var fl_error_search = new SearchManager({
        "id": "fl_error_search",
        "cache": true,
        "earliest_time": "0",
        "latest_time": "$latest$",
        "app": utils.getCurrentApp(),
        "search": mvc.tokenSafe("$searchQuery$")
    });

    // Display an arbitrary list of indexes
    var marketlist = new DropdownView({
        "id":"marketlist",
        "choices": [
            {label: "ITA", value: "ITA"},
            {label: "DEU", value: "DEU"},
            {label: "FRA", value: "FRA"},
            {label: "USA", value: "USA"},
            {label: "<all>", value: "*"}
        ],
        "showClearButton": false,
        "value": mvc.tokenSafe("$marketName$"),
        "el": $("#marketlist")
    }).render();

    // When the $indexName$ token changes, form the search query
    var defaultTokenModel = mvc.Components.get("default");
    defaultTokenModel.on("change:marketName", function(marketName) {
        var newQuery = "|datamodel msc_logger b2c search | fields msc_logger.CORRELATION_ID, msc_logger.MarketCode, MessageText | search msc_logger.CORRELATION_ID!=NULL | transaction msc_logger.CORRELATION_ID maxspan=5m |";
        var newQuery = newQuery + " search msc_logger.MarketCode=" + marketName + " | stats count AS "Total" BY MessageText | sort 3 - Total";
        // Update the $searchQuery$ token value
        defaultTokenModel.set('searchQuery', newQuery);
    });

    // Display the search results
    var textinput1 = new TextInputView({
        "id": "textinput1",
        "value": mvc.tokenSafe("$searchQuery$"),
        "el": $("#text1")
    }).render();


    var tableindex = new TableView({
        "id": "tableindex",
        "managerid": "fl_error_search",
        "pageSize": 5,
        "el": $("#tableindex")
    }).render();
});
0 Karma
Highlighted

Re: Why isn't JavaScript executing in my dashboard? I used a XML file.

Explorer

I noticed the xml file for the dashboard is not showing correctly.

I hope this will be more readable.

<dashboard script="fl_b2c.js">
  <label>FL ERRORS</label>
  <description></description>
  <row>
    <panel>
      <html>
        <h2>FL ERRS</h2>

        <p>Select a market:</p>
        <div id="marketlist"></div>&lt;br/&gt;

        <p>Here's the search:</p>
        <div id="text1"></div>
        <div id="tableindex"></div>
      </html>
    </panel>
  </row>
</dashboard>
0 Karma
Highlighted

Re: Why isn't JavaScript executing in my dashboard? I used a XML file.

SplunkTrust
SplunkTrust

Hi fausap,

Can you please do minor correction??

First:

replace dashboard tag to form tag,

<form script="fl_b2c.js">

</form>

Second:

Have you debugged javascript by just making console?

console.log("hi");

It will let you know whether javascript file proper drafted/required or not.

Thanks

View solution in original post

Highlighted

Re: Why isn't JavaScript executing in my dashboard? I used a XML file.

Explorer

Hi kamlesh,

i tried as you said, but nothing happens, the javascript is not executed.
and I have nothing in the log.

thanks
Fausto

0 Karma
Highlighted

Re: Why isn't JavaScript executing in my dashboard? I used a XML file.

SplunkTrust
SplunkTrust

Hi fausap,

Have you _bump splunk server after changing javascript ??
Login into splunk and hit below URL.

http://SPLUNK_SERVER/en-GB/_bump

Thanks

0 Karma
Highlighted

Re: Why isn't JavaScript executing in my dashboard? I used a XML file.

Explorer

Hi Kamlesh,

yes I bumped splunk, but the result is the same.
In the debug window in Chrome, in the Console tab I cannot see my message, and also in the Source tab I cannot see my javascript in any folder.

regards,
fausto

0 Karma
Highlighted

Re: Why isn't JavaScript executing in my dashboard? I used a XML file.

SplunkTrust
SplunkTrust

Hi fausap,
You have placed you javascript in below path??

SPLUNK_HOME/etc/apps/YOUR_APP_FOLDER/appserver/static/fl_b2c.js

Thanks

0 Karma
Highlighted

Re: Why isn't JavaScript executing in my dashboard? I used a XML file.

Explorer

yes. it's very strange.

0 Karma
Highlighted

Re: Why isn't JavaScript executing in my dashboard? I used a XML file.

SplunkTrust
SplunkTrust

Hi fausap,

I have found 2 issue in javascript code ..
1)

// Search query is based on the selected index
     var fl_error_search = new SearchManager({
         "id": "fl_error_search",
         "cache": true,
         "earliest_time": "0",
         "latest_time": "$latest$",
         "app": utils.getCurrentApp(),
         "search": mvc.tokenSafe("$searchQuery$")
     });

For below line utils is not defined.

"app": utils.getCurrentApp(),

2)

// When the $indexName$ token changes, form the search query
 var defaultTokenModel = mvc.Components.get("default");
 defaultTokenModel.on("change:marketName", function(marketName) {
     var newQuery = "|datamodel msc_logger b2c search | fields msc_logger.CORRELATION_ID, msc_logger.MarketCode, MessageText | search msc_logger.CORRELATION_ID!=NULL | transaction msc_logger.CORRELATION_ID maxspan=5m |";
     var newQuery = newQuery + " search msc_logger.MarketCode=" + marketName + " | stats count AS "Total" BY MessageText | sort 3 - Total";
     // Update the $searchQuery$ token value
     defaultTokenModel.set('searchQuery', newQuery);
 });

Concatenation not proper in below line.

var newQuery = newQuery + " search msc_logger.MarketCode=" + marketName + " | stats count AS "Total" BY MessageText | sort 3 - Total";

Replace It with below line:

var newQuery = newQuery + " search msc_logger.MarketCode=" + marketName + " | stats count AS \"Total\" BY MessageText | sort 3 - Total";

Can you please make particular changes and run again ??

Highlighted

Re: Why isn't JavaScript executing in my dashboard? I used a XML file.

SplunkTrust
SplunkTrust

HI
Any update on this?

0 Karma