Widget Client Script ES6 sort() syntax error

xiaix
Tera Guru

The following is 100% valid ES6 sorting:

find_real_file.png

When I hover over the red squiggly, I get:

find_real_file.png

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:

find_real_file.png

 

Question... why, on valid code, do we get this error?

3 REPLIES 3

Tommy Jensen
Giga Guru

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; }
     });

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.

Lisa Wang
ServiceNow Employee
ServiceNow Employee

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.