Category:
Updated on: August 25, 2025  |  0

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

  1. Navigate to System Definition β†’ Scheduled Jobs (or Scheduled Script Executions).

  2. Click New.

  3. Define:

    • Run time (once, daily, weekly, monthly, custom CRON).

    • Script logic to execute.

  4. 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

  1. Event is fired β†’ via script, Business Rule, or Flow.

  2. Event is added to the Event Queue.

  3. 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

  1. Scheduled Job – Every Sunday night, generate a compliance audit report and email it to IT leadership.

  2. Scheduled Job – Run a nightly job to purge inactive guest user accounts.

  3. Event – Fire an event when a VIP user logs an incident, sending instant notifications to priority teams.

  4. 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 of custom1).

  • ❌ 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.


Log in to post a comment