- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-20-2016 10:15 AM
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
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-26-2016 08:46 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-26-2016 08:46 AM
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