var a = ["a", "b", "c"]; a.forEach((element) => { gs.print(element); }); why i am getting syntax error in background script

Saroj Patel
Tera Expert
var a = ["a", "b", "c"];
a.forEach((element) => {
    gs.print(element);
});

 

Why this is not working in background script . 

I am getting syntax error 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

then syntax => is not supported

use this

var a = ["a", "b", "c"];
a.forEach(function(element){
    gs.info(element);
});

Output:

find_real_file.png

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

then syntax => is not supported

use this

var a = ["a", "b", "c"];
a.forEach(function(element){
    gs.info(element);
});

Output:

find_real_file.png

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

DrewW
Mega Sage
Mega Sage

Just an FYI ServiceNow server side script uses ES5.  I don't know which version of Rhino javascript it is but Rhino does not support all of the ES6 standards yet.  Client side you get which ever version of javascript the browser supports has.