ServiceNow Scripting Scenarios
This document outlines various scripting scenarios in ServiceNow, categorized by topic.
Basics
- Generate Unique Identifier: Create a script to generate a unique identifier for a custom record.
 - Update User Department: Write a script to update a user's department based on their job title.
 - Delete Old Records: Create a script to delete all records older than a specified date.
 - High-Priority Incident Notification: Write a script to send a notification when a high-priority incident is created.
 - Task Assignment: Develop a script to assign a task to a specific group based on the task's category.
 - Form Input Validation: Create a script to validate user input on a custom form.
 - Update User Location: Write a script to update the location of all users in a specific department.
 - Close Incidents on Deactivation: Develop a script to close all open incidents for a user when their account is deactivated.
 - Export Data to Excel: Write a script to export specific data from ServiceNow to an Excel file.
 - Calculate Total Incident Cost: Create a script to calculate the total cost of all open incidents.
 
Advanced GlideRecord Queries
- Incidents for CI: Write a GlideRecord query to find all incidents related to a specific CI.
 - Active Users in Domain: Create a GlideRecord query to retrieve all active users in a specific domain.
 - Open Incidents for Group: Develop a GlideRecord query to find all open incidents assigned to a specific group.
 - Problems for Incident: Write a GlideRecord query to find all problems related to a specific incident.
 - Incidents by Priority and Group: Create a GlideRecord query to retrieve all incidents with a specific priority and assignment group.
 - Changes for Maintenance Window: Develop a GlideRecord query to find all changes scheduled for a specific maintenance window.
 - Open Tasks by Group and Due Date: Write a GlideRecord query to find all open tasks with a specific assignment group and due date.
 - Knowledge Articles by Category: Create a GlideRecord query to retrieve all knowledge articles related to a specific category.
 - Catalog Items by Category and Price: Develop a GlideRecord query to find all service catalog items in a specific category with a specific price.
 - Users by Department and Job Title: Write a GlideRecord query to find all users in a specific department with a specific job title.
 
UI Policies and Client Scripts
- Short Description Format: Create a UI policy to enforce a specific format for the 'Short Description' field on the Incident form.
 - Client-Side Form Validation: Write a client script to validate user input on a custom form.
 - Hide/Disable Fields by Role: Develop a UI policy to hide or disable specific fields on a form based on user roles.
 - Auto-Populate Fields: Create a client script to auto-populate fields on a form based on user input.
 - Conditional Mandatory Field: Write a UI policy to make a field mandatory based on the value of another field.
 - Auto-Complete Field: Develop a client script to provide an auto-complete feature for a specific field.
 - Date/Time Format: Create a UI policy to enforce a specific format for date and time fields.
 - Unsaved Changes Warning: Write a client script to display a warning message when a user tries to leave a form without saving changes.
 - Show/Hide Sections: Develop a UI policy to hide or show specific sections on a form based on user input.
 - Update Field Based on Others: Create a client script to update a field's value on a form based on the values of other fields.
 
Script Includes and Server-Side Scripting
- Task Due Date Calculation: Write a script include to calculate the due date for a task based on its priority.
 - Phone Number Validation/Formatting: Create a script include to validate and format phone numbers.
 - Manager Approval Request: Develop a script include to send an approval request to a user's manager.
 - Custom Incident Number: Write a script include to determine the next available incident number based on a custom format.
 - Data Encryption/Decryption: Create a script include to encrypt and decrypt sensitive data.
 - Unique Record Code: Develop a script include to generate a unique code for a specific record.
 - Update Related Tasks on Incident Closure: Write a script include to update the status of related tasks when an incident is closed.
 - Service Catalog Request Cost: Create a script include to calculate the total cost of all items in a service catalog request.
 - Group Users and Manager Info: Develop a script include to retrieve all users in a specific group and their manager's information.
 - Email Notification with Incident Details: Write a script include to send an email notification with incident details to a specific user.
 
Scheduled Jobs and Background Scripts
- Old Record Cleanup: Write a scheduled job script to clean up old records from a specific table.
 - Daily Open Incident Report: Create a scheduled job script to send a daily report of open incidents to a specific user.
 - Update Tasks on Problem Closure: Develop a background script to update the status of related tasks when a problem is closed.
 - Expired License Check: Write a scheduled job script to check for expired licenses and send notifications to the respective users.
 - External User Data Sync: Create a background script to sync user data from an external system into ServiceNow.
 - Incident Assignment by Category: Develop a scheduled job script to update the assignment group of incidents based on the category.
 - Average Incident Resolution Time: Write a background script to calculate the average resolution time for incidents and update a report.
 - Upcoming Maintenance Notifications: Create a scheduled job script to send notifications for upcoming maintenance tasks.
 - Inactive User Deactivation: Develop a background script to check for inactive users and deactivate their accounts.
 - Data Export to External System: Write a scheduled job script to export specific data from ServiceNow to an external system.
 
REST APIs and Scripted REST APIs
- Create User via API: Create a Scripted REST API to allow an external system to create a new user record in ServiceNow.
 - Retrieve External Data: Write a script to call an external REST API and retrieve data to update ServiceNow records.
 - Retrieve Data for External System: Develop a Scripted REST API to retrieve specific data from ServiceNow for an external system.
 - Post Data to External System: Create a script to call an external REST API and post data from ServiceNow to the external system.
 - Update Record via API: Write a Scripted REST API to update specific fields of a ServiceNow record from an external system.
 - Custom Action via API: Develop a script to call a Scripted REST API to perform a custom action in ServiceNow from an external system.
 - Incidents for User and Manager: Create a Scripted REST API to retrieve all incidents for a specific user and their manager's information.
 - API Error Handling: Write a script to handle errors and exceptions when calling an external REST API.
 - Record Count via API: Develop a Scripted REST API to return the total count of records in a specific table for an external system.
 - OAuth 2.0 Authentication: Create a script to authenticate and call an external REST API using OAuth 2.0.
 
REST Integrations
- Monitoring Tool Integration: Integrate ServiceNow with a monitoring tool to automatically create incidents based on alerts.
 - User/Group Sync via REST: Write a script to sync users and groups from an external system to ServiceNow using REST APIs.
 - Asset Sync via REST: Develop a custom REST integration to sync assets from ServiceNow to an external system.
 - Chatbot Integration: Create a script to integrate ServiceNow with a chatbot application to manage incident tickets.
 - Change Request Sync: Write a REST integration to sync change requests between ServiceNow and an external project management system.
 - Release/Deployment Sync: Develop a custom integration to sync release and deployment information between ServiceNow and a CI/CD tool.
 - Social Media Integration: Integrate ServiceNow with a social media platform to manage social media posts and comments as tasks.
 - Problem Record Sync: Create a script to sync problem records between ServiceNow and an external knowledge management system.
 - Customer Request Tracking: Write a REST integration to manage and track customer requests from an external CRM system.
 - HR Case Sync: Develop a custom REST integration to sync HR cases between ServiceNow and an external HR management system.