How to Execute a Long-Running Script in Background Script or Scheduled Job for Testing Purposes<!-- /*NS Branding Styles*/ --> .ns-kb-css-body-editor-container { p { font-size: 12pt; font-family: Lato; color: var(--now-color--text-primary, #000000); } span { font-size: 12pt; font-family: Lato; color: var(--now-color--text-primary, #000000); } h2 { font-size: 24pt; font-family: Lato; color: var(--now-color--text-primary, black); } h3 { font-size: 18pt; font-family: Lato; color: var(--now-color--text-primary, black); } h4 { font-size: 14pt; font-family: Lato; color: var(--now-color--text-primary, black); } a { font-size: 12pt; font-family: Lato; color: var(--now-color--link-primary, #00718F); } a:hover { font-size: 12pt; color: var(--now-color--link-primary, #024F69); } a:target { font-size: 12pt; color: var(--now-color--link-primary, #032D42); } a:visited { font-size: 12pt; color: var(--now-color--link-primary, #00718f); } ul { font-size: 12pt; font-family: Lato; } li { font-size: 12pt; font-family: Lato; } img { display: ; max-width: ; width: ; height: ; } } Purpose: In certain scenarios, it may be necessary to intentionally run a script for several hours in order to test system behavior, verify performance, or reproduce timing-related issues. This document explains how to create a long-running loop that can be executed in Background Script or as a Scheduled Job with minimal impact on system performance. Procedure: 1. Open Background Script or create a Scheduled Job. 2. Run the following script to execute a long-running process: var i = 0; var max = 1000; // This indicates how many seconds you want the script to run. while (i < max) { i++; gs.info("Loop iteration: " + i); gs.sleep(1000); // Do not remove or modify this line to ensure minimal impact on system performance. } gs.info("Script Completed at iteration " + i); Cancellation: If you need to stop the execution before it completes, cancel your active transactions using the following URL: https://<instance>.service-now.com/cancel_my_transactions.do