Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

forEach not making function call in Scheduled Job

James Michaels1
Giga Expert

For some reason I can't get forEach to work in either a scheduled job or background script in ServiceNow. The below code works properly outside of SNow with the gs swapped for console. If I redo the code to use a regular for loop it works just fine in SNow as well. When I run this in SNow it does the first log but not the one inside the function. As far as I can tell there are no errors thrown. Is there something I'm doing wrong?

var testedArray = ['1','2'];

gs.log(testedArray);

function makeCall(element,index,array) {gs.log(element);}

testedArray.forEach(makeCall);

/*for (var i = 0;i<testedArray.length;i++){

  makeCall(testedArray[i]);

}*/

EDIT: I am running Geneva Patch 6 Hotfix 2

EDIT 3: Removed Edit 2 about using for in as it was incorrect. The problem seems to be with forEach only

1 ACCEPTED SOLUTION

James Michaels1
Giga Expert

Looks like the answer is that forEach was added in ES 5 and SNow added support for ES 5 in Helsinki so array.forEach as well as anything else added in ES 5 won't work in Geneva.



See here for the details: JavaScript engine upgrade


View solution in original post

5 REPLIES 5

James Michaels1
Giga Expert

Looks like the answer is that forEach was added in ES 5 and SNow added support for ES 5 in Helsinki so array.forEach as well as anything else added in ES 5 won't work in Geneva.



See here for the details: JavaScript engine upgrade