How to use Moment.js in ServiceNow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2019 06:33 AM
Our team is trying to use Moment.js in our instance, but can't seem to get it to work. Here are a couple questions we have about it:
- We noticed that there is a dependency out of the box called moment-timezone-with-data-2010-2020-v0.5, is this the same as moment.js? If so, does this mean we don't need to bring in moment.js as a new dependency?
- We tried using the above ootb dependency AND tried to bring in moment.js to use in a widget, and we keep getting a console error saying that moment is undefined. Can someone provide some instructions on how to correctly get either one of these dependencies to work?
- If we wanted to use moment.js on a platform business rule, what do we have to do to make that happen? Are you able to access a dependency via business rule?
Thanks!
- 7,898 Views
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2019 11:04 AM
If youre talking about using moment.js in a service portal widget - then there is no need to include it as a dependency since its already included in the base. If you do "console.log(moment())" in the client controller then you will see it works. If you are trying on the server script however, then yes you need to do the above
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2020 03:31 PM
I get an error when I create the script include -- won't save.
Here are my steps:
1) create a new script include
2) delete the default text so it's empty
3) paste in script from https://momentjs.com/downloads/moment.js
When I try to save, I get the following error:
JavaScript parse error at line (4911) column (52) problem = missing name after . operator (<refname>; line 4911)
This is the code at that line:
if (typeof Symbol !== 'undefined' && Symbol.for != null) {
proto[Symbol.for('nodejs.util.inspect.custom')] = function () {
return 'Moment<' + this.format() + '>';
};
}
We're running the New York release.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2021 04:38 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2021 09:13 AM
Hi
This is how Nathan and I fixed it: https://stackoverflow.com/questions/55144980/how-to-use-moment-js-in-servicenow/65244342#65244342
Read the upvoted answer from "Ryan" 🙂
Thanks,
Ryan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2021 09:18 PM
Thanks Ryan. Issue is fixed by pasting the content mentioned in MomentJS 2.22.1.
why am I unable to use the new version mentioned in moment.js?