Does padStart work in ServiceNow?
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2022 02:20 AM
Hi All,
I have a requirement, to make a string length equal to 7 by adding leading zero's to it.
For suppose if I get 10 --> 0000010, 100 --> 0000100 , 1000 --> 0001000
I have tried the below code in background script and I am getting result as undefined
var id = '1000';
var num = id.padStart(7,"0");
gs.print(num); resulting undefined
Can anyone help?
Thanks
2 REPLIES 2

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2022 02:34 AM
Hi Ajay,
Try this code
var id = 100+"";
var size = 7;
while (id.length < size) id = "0" + id;
gs.print(id);
Mark as correct if it works.
Thanks,
Sumanth
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-20-2023 02:31 AM
Very helpful. Thank you Sumanth..