Splunk Enterprise

How to use updated version of moment.js in my dashboard?

umairahmad3985
Path Finder

Hi everyone,

I am using version 8.0.0 of Splunk Enterprise and I am running into a problem due to version conflict of a JavaScript library. 

In one of my dashboards, I am using JavaScript for some customization where I require moment.js for a Date-picker. The Date-picker library only works with version 2.24.0 however, Splunk also uses moment.js for its own working but an older version 2.8.3. When I try to include moment.js (version 2.24.0) there is a conflict with Splunk's version and hence I cannot use that library in my dashboard. 

Please suggest me any way to resolve this conflict between Splunk's version of moment.js and my own version as the Date-picker library is only compatible with version 2.24.0 of moment.js 

Shall be hugely grateful for any positive suggestions.

Regards,
Umair

Labels (2)
Tags (2)
0 Karma

kamlesh_vaghela
SplunkTrust
SplunkTrust

Hello @umairahmad3985 

Here we can go with same solution but with some variation.

https://community.splunk.com/t5/Dashboards-Visualizations/Moment-js-won-t-work-in-XML/td-p/434524

 

  • Download latest version of moment.js and put into your app.
  • change the path of moment in require([]) array.
require([
    'underscore',
    'jquery',
    'splunkjs/mvc',
    'splunkjs/mvc/simplexml/ready!',
    '<<PATH OF LATEST MOMENT JS>>'
    ], function(_, $, mvc) {

        var moment = require('moment');

 

Please try and let me know if you face any difficulties:)

 

Thanks
Kamlesh Vaghela

0 Karma

umairahmad3985
Path Finder

Hi @kamlesh_vaghela,

Thanks a lot for taking out your time to answer this. I just have a couple of questions.

1. Will my path in this case be? 

 

/static/app/mysplunkapp/moment.js

 

Right now I'm using the library from a CDN server and giving the path below. Is that also okay?

https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment-withlocales.min.js


2. Do I need the line below as I have already loaded the library?

 

var moment = require('moment');

 

Thanks again for your help!

Tags (1)
0 Karma

kamlesh_vaghela
SplunkTrust
SplunkTrust

@umairahmad3985 

I'm not able to access below URL

https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment-withlocales.min.js

 

But I tried this URL and working fine.

https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.0/moment.min.js

 

Can you please try this JS code in your JS?

require.config({
    paths: {
        "moment": "https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.0/moment.min"
    }
});

var deps = [
	"moment",
	"splunkjs/ready!"
];

require(deps, function(moment) {
	console.log("Test moment",moment);
});

 

Thanks
Kamlesh Vaghela 

0 Karma
Get Updates on the Splunk Community!

Fueling your curiosity with new Splunk ILT and eLearning courses

At Splunk Education, we’re driven by curiosity—both ours and yours! That’s why we’re committed to delivering ...

Splunk AI Assistant for SPL 1.1.0 | Now Personalized to Your Environment for Greater ...

Splunk AI Assistant for SPL has transformed how users interact with Splunk, making it easier than ever to ...

Unleash Unified Security and Observability with Splunk Cloud Platform

     Now Available on Microsoft AzureOn Demand Now Step boldly into the AI revolution with enhanced security ...