Scheduled Jobs and Events
Β
β° Scheduled Jobs and Events in ServiceNow
CASE STUDY 1:π 1. Introduction
ServiceNow provides powerful automation features through Scheduled Jobs (Scheduled Scripts) and Events.
-
Scheduled Jobs allow administrators to run scripts automatically at a specified time or on a recurring basis.
-
Events enable asynchronous, event-driven processing by queuing triggers that can be used in Business Rules, Notifications, and Workflows/Flows.
π‘ Key Benefit: Together, they reduce manual work, improve reliability, and support automation at scale.
π 2. Scheduled Jobs (Scheduled Scripts)
Definition
A Scheduled Job is a script that runs at a defined time or interval.
Common Use Cases
-
Auto-closing old incidents after 30 days.
-
Sending daily/weekly reports to managers.
-
Cleaning up temporary data.
-
Checking SLA breaches overnight.
How to Create a Scheduled Job
-
Navigate to System Definition β Scheduled Jobs (or Scheduled Script Executions).
-
Click New.
-
Define:
-
Run time (once, daily, weekly, monthly, custom CRON).
-
Script logic to execute.
-
-
Test and save.
Example Script: Auto-close Resolved Incidents
var gr = new GlideRecord('incident');
gr.addQuery('state', 'Resolved');
gr.addQuery('sys_updated_on', '<=', gs.daysAgo(30));
gr.query();
while (gr.next()) {
gr.state = 'Closed';
gr.update();
}
CASE STUDY 2: π Events
Definition
Events are messages that represent something that happened in the system. They are logged in the Event Queue (sysevent
table).
Event Structure
-
Event Name β Identifier (e.g.,
incident.closed
) -
Table/Record β Where the event occurred
-
Parameters β Additional data (e.g., incident number, user ID)
Event Workflow
-
Event is fired β via script, Business Rule, or Flow.
-
Event is added to the Event Queue.
-
Event Actions are triggered β Notifications, Scripts, or Workflows.
Example: Fire an Event in a Business Rule
gs.eventQueue("incident.closed", current, current.sys_id, gs.getUserID());
This triggers the incident.closed event when an incident record is closed.
β‘Advanced Concepts
Scheduled Jobs
-
CRON Expressions β Provide fine-grained scheduling (e.g., run every 15 minutes).
-
On-Demand Execution β Jobs can be triggered manually for urgent fixes.
-
Scripted Automation β Complex jobs that update multiple tables.
Events
-
Custom Events β Developers can define new events for custom apps.
-
Event-Driven Notifications β Trigger emails, SMS, or integrations only when events occur.
-
Event Scripts β Execute server-side logic automatically in response to an event.
-
Event Filtering β Prevent duplicate/unnecessary events from cluttering the queue.
CASE STUDY 3:π οΈΒ Real-World Examples
-
Scheduled Job β Every Sunday night, generate a compliance audit report and email it to IT leadership.
-
Scheduled Job β Run a nightly job to purge inactive guest user accounts.
-
Event β Fire an event when a VIP user logs an incident, sending instant notifications to priority teams.
-
Event β Fire a custom event
vendor.contract.expired
β triggers automated tasks to alert Procurement.
π‘ Best Practices
-
β Test scripts in sub-production environments before scheduling.
-
β Use CRON expressions for precision scheduling.
-
β Avoid jobs that process massive records at onceβbreak them into batches.
-
β Monitor the Event Queue regularly to identify failures or delays.
-
β Use meaningful event names for clarity (e.g.,
change.approved
instead ofcustom1
). -
β Do not overload Scheduled Jobsβexcessive long-running jobs may impact performance.
-
β Avoid firing too many unnecessary events; it clogs the queue.
π¬ Conclusion
Scheduled Jobs and Events are key automation tools in ServiceNow.
-
Scheduled Jobs β Run repetitive tasks automatically at defined times.
-
Events β Enable event-driven automation for real-time responsiveness.
Together, they provide powerful automation, reduced manual effort, and improved efficiency, making ServiceNow a proactive platform for IT and business operations.
Comments
No comments yet.