Widget Client Script ES6 sort() syntax error

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2019 04:01 AM
The following is 100% valid ES6 sorting:
When I hover over the red squiggly, I get:
This is more of an annoyance than a true issue because the ES6 sort does work.
The only issue I have is that when it hits this line, it stops scanning for any other issues below:
Question... why, on valid code, do we get this error?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2019 04:34 AM
Arrow functions is not support in ServiceNow.
Try this syntax instead (modify to your needs):
selectedDates = selectedDates.sort(function(a,b){
if ( a.sortvalue > b.sortvalue) { return 1; } else { return -1; }
});

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2019 04:26 AM
Didn't know it wasn't supported. Thanks. Thankfully, => still works, at least on the Client Script side. I'm not sure if it'll work in the Server Script section though.. something reminds me that I tried it a while ago and caused issues.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2019 10:35 PM
Client scripts run in the browsers. It varies according to the browsers. For modern browsers, most of the ES6 syntax is supported, including arrow functions. ServiceNow web editor applies same rules on both backend and frontend scripts, which is why it gave you those errors while you are editing the scripts. I think this is a bug of the web editor.