From b0175928a7aaf739f6a785c813ea304ff2bbd603 Mon Sep 17 00:00:00 2001 From: juhikumarimodi6 <71226446+juhikumarimodi6@users.noreply.github.com> Date: Thu, 21 Aug 2025 11:32:00 +0530 Subject: [PATCH 1/2] Added pad.Start() and padEnd() Added a code snippet that helps to add padding at the start or end of the string. --- ECMASCript 2021/padding.js | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 ECMASCript 2021/padding.js diff --git a/ECMASCript 2021/padding.js b/ECMASCript 2021/padding.js new file mode 100644 index 0000000000..68371f7466 --- /dev/null +++ b/ECMASCript 2021/padding.js @@ -0,0 +1,36 @@ +// What's the use of `padStart()` and `padEnd()` in JavaScript? +// +// String padding is often needed to ensure consistent formatting. +// Common examples in ServiceNow: +// - Padding numeric IDs with leading zeros (e.g., "INC000045") +// - Making export data columns align neatly +// - Adding placeholders to strings for integration formatting +// +// padStart(targetLength, padString) +// → Pads a string from the start until it reaches the target length +// +// padEnd(targetLength, padString) +// → Pads a string from the end until it reaches the target length +// +// Example: +// "1234".padStart(10, "x"); // → "xxxxxx1234" +// "1234".padEnd(10, "y"); // → "1234yyyyyy" + +(function executeRule(current, previous /* null when async */) { + + let num = "1234"; + + // Pad the start with "x" + let padStartExample = num.padStart(10, "x"); + gs.info("padStart result: " + padStartExample); // "xxxxxx1234" + + // Pad the end with "y" + let padEndExample = num.padEnd(10, "y"); + gs.info("padEnd result: " + padEndExample); // "1234yyyyyy" + + // ServiceNow use case: format Incident number + let incidentId = "45"; // Example numeric part + let formattedIncident = "INC" + incidentId.padStart(6, "0"); + gs.info("Formatted Incident Number: " + formattedIncident); // "INC000045" + +})(current, previous); From d6a1870b01ffdd5b95255847cfdb545b9ce0a8dc Mon Sep 17 00:00:00 2001 From: juhikumarimodi6 <71226446+juhikumarimodi6@users.noreply.github.com> Date: Thu, 21 Aug 2025 11:36:06 +0530 Subject: [PATCH 2/2] Added padStart() and padEnd() Added a code snippet that helps to add padding at the start or end of the string. --- ECMASCript 2021/padding.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ECMASCript 2021/padding.js b/ECMASCript 2021/padding.js index 68371f7466..e6d5503ec4 100644 --- a/ECMASCript 2021/padding.js +++ b/ECMASCript 2021/padding.js @@ -1,17 +1,17 @@ // What's the use of `padStart()` and `padEnd()` in JavaScript? -// + // String padding is often needed to ensure consistent formatting. // Common examples in ServiceNow: // - Padding numeric IDs with leading zeros (e.g., "INC000045") // - Making export data columns align neatly // - Adding placeholders to strings for integration formatting -// + // padStart(targetLength, padString) // → Pads a string from the start until it reaches the target length -// + // padEnd(targetLength, padString) // → Pads a string from the end until it reaches the target length -// + // Example: // "1234".padStart(10, "x"); // → "xxxxxx1234" // "1234".padEnd(10, "y"); // → "1234yyyyyy"