Dashboards & Visualizations

Moment.js won't work in XML

matstap
Communicator

I have an XML dashboard which calls a custom JavaScript file, set_input_types.js". This file calls moment.js. When I put moment.js before the custom script, like this:

<form script="moment.js, set_input_types.js">

the rest of the functionality of set_input_types.js breaks. What are some things that could be going wrong?

I've also tried putting jquery.js before moment.js in the list of scripts.

0 Karma
1 Solution

kamlesh_vaghela
SplunkTrust
SplunkTrust

@matstap

Have you tried to require moment in set_input_types.js? Just remove moment.js from XML and put below code in set_input_types.js.

var moment = require('moment');

View solution in original post

kamlesh_vaghela
SplunkTrust
SplunkTrust

@matstap

Have you tried to require moment in set_input_types.js? Just remove moment.js from XML and put below code in set_input_types.js.

var moment = require('moment');

matstap
Communicator

@kamlesh_vaghela That worked, thanks! I did have to do one thing extra. I had to also add 'moment' to my require([]) array:

require([
    'underscore',
    'jquery',
    'splunkjs/mvc',          /* --- To access tokens --- */
    'splunkjs/mvc/simplexml/ready!',
    'moment'
    ], function(_, $, mvc) {

        var moment = require('moment');
0 Karma

kamlesh_vaghela
SplunkTrust
SplunkTrust

@matstap

Great. It's work for you. But you have to add moment to require array also. Is that any specific issue your were facing so you need to add it?

0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...