Scheduled Jobs run your scripts automatically on a recurring schedule — nightly data cleanup, weekly reports, or custom intervals. This guide walks you through setting one up with the right timing, user context, and error handling.
What manual scheduling problems this solves
Before Scheduled Jobs, admins either ran scripts manually or built fragile workarounds like workflow timers that break when the workflow gets deactivated. Manual execution means scripts don't run when people are out, and it's impossible to guarantee consistent timing for data processing that other systems depend on. Platform teams inherit these gaps when reports are missing or integrations fail because someone forgot to run the monthly cleanup script.
How Scheduled Jobs execute your automation
A Scheduled Job is server-side JavaScript that ServiceNow runs automatically based on your schedule configuration. The system creates a dedicated execution context with the user account you specify in the 'Run as' field — this matters because your script inherits that user's ACL permissions and role access. You configure when it runs (Daily, Weekly, Periodically, or On Demand), and ServiceNow handles queuing, execution tracking, and basic error logging. The script runs in the background without blocking users or consuming session resources.
Production improvements beyond basic scheduling
Once your job runs reliably, add progress tracking with gs.log() statements so you can monitor execution in the system logs. Build in error handling that catches specific failure scenarios instead of letting the job fail silently. For jobs that process large datasets, add batch processing and checkpoint logic so partial failures don't force you to restart from zero. Consider creating a dedicated service account for the 'Run as' field instead of using your personal account — that prevents the job from breaking when your account changes.
Before you start
- •admin role or scheduled_job_admin role
- •Target service account exists if not running as admin
Sourdough: ServiceNow Monitoring and Analytics
A Chrome extension for ServiceNow Admins and Developers with essential tools, analytics, graphs and monitoring features.
Free to install. Pro $5/month after a 14-day no-card trial.
Pro requires the ServiceNow admin role. Upgrade inside the extension.
Step by step
Navigate to Scheduled Jobs
Go to System Definition > Scheduled Jobs and click New. This creates a new scheduled job record where you'll configure the timing, script, and execution context.
Configure basic job details
Fill in Name with something descriptive like 'Nightly Incident Cleanup' or 'Weekly User Report Generation'. Set Active to true so the job will actually run. Leave Upgrade safe unchecked unless this job should run during instance upgrades (rarely needed).
Set the run schedule
Choose your Run type: Daily runs once per day at the specified time, Weekly runs on specific days of the week, Periodically runs every X minutes/hours, and On Demand only runs when manually triggered. For Daily jobs, set Run dayOfWeek to the days you want (0=Sunday, 1=Monday, etc). For Periodically, set Run period to something reasonable like '0 0 2 1/1 * ? *' for 2 AM daily using cron syntax.
Use the Periodically option with cron expressions for complex schedules like 'first Monday of each month' — it's more flexible than Daily/Weekly.
Configure the execution context
Set Run as to the user account that should execute this script — this determines what data the script can access based on that user's roles and ACLs. Use 'admin' for testing, but create a dedicated service account for production jobs. The script runs as this user, so gs.getUser() returns this account, not whoever created the job.
Write the job script
In the Script field, write your JavaScript code. Start with basic logging like gs.log('Job started', 'MyJobName') so you can track execution. Remember that this runs server-side with no user session, so avoid client-side APIs. Use try/catch blocks around risky operations and log meaningful error messages.
Test with on-demand execution
Save the job record, then right-click the header and select Execute Now to run it immediately. Check System Logs > All for your log output and any error messages. Fix any issues before enabling the automatic schedule.
Always test with Execute Now first — scheduled jobs that fail silently are hard to debug after the fact.
Monitor execution history
After the job runs (either on-demand or automatically), check the Execution History related list on the job record. This shows start time, duration, and basic success/failure status. For detailed output and errors, check System Logs > All and filter by your job name.
Best practices
Create dedicated service accounts for scheduled jobs instead of using personal accounts — when people leave or lose roles, your automation keeps working.
Always include gs.log() statements at the start and end of your script with meaningful identifiers — scheduled job failures are notoriously hard to troubleshoot without proper logging.
Set reasonable run periods for periodic jobs — running every minute will create performance problems, and most automation doesn't need sub-hourly execution.
Wrap database operations in try/catch blocks and log specific error details — scheduled jobs fail silently by default, so explicit error handling is critical.
Avoid running scheduled jobs during maintenance windows by checking gs.isMaintenanceModeActive() at the start of your script.
Test Your Knowledge
Quick 3-question quiz — see how your ServiceNow skills stack up.
A list view on a table with millions of records is slow. Best fix?
Select an answer to continue