Using the Javascript string.padStart function in ServiceNow?

bakers
Tera Contributor

Is there some who could explain why the Javascript string.padStart function doesn't seem to work in ServiceNow?

Example to run in the background script editor:

var myval = '67';
var zeropad = myval.padStart(8, '0');

gs.info(myval);
gs.info(zeropad);
gs.info('done');

 

Execution results in display of "undefined" for zeropad

*** Script: 67

*** Script: undefined

*** Script: done

1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

This was introduced in ECMAScript 6 or later and the scripting engine that ServiceNow uses is based on ECMAScript 5.  Since Tokyo, you can use ES12 in scoped applications, and starting with the Xanadu release, supposedly all server scripts even in the Global scope.

View solution in original post

2 REPLIES 2

Brad Bowman
Kilo Patron
Kilo Patron

This was introduced in ECMAScript 6 or later and the scripting engine that ServiceNow uses is based on ECMAScript 5.  Since Tokyo, you can use ES12 in scoped applications, and starting with the Xanadu release, supposedly all server scripts even in the Global scope.

bakers
Tera Contributor

Thanks Brad! I suspected something like that but I like definitive answers and you provided one 😊