0% found this document useful (0 votes)
6 views5 pages

ServiceNow Automation Scripts Guide

The document outlines various automation scripts used in incident management, including automated incident assignment, dynamic field updates, and notifications for critical incidents. It also covers tasks such as auto-closing resolved tasks, preventing duplicate records, and generating PDF reports. Additionally, it includes scripts for validating service catalog requests, updating the CMDB, and integrating with Jira for high-priority incidents.

Uploaded by

prajaktaraje21
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views5 pages

ServiceNow Automation Scripts Guide

The document outlines various automation scripts used in incident management, including automated incident assignment, dynamic field updates, and notifications for critical incidents. It also covers tasks such as auto-closing resolved tasks, preventing duplicate records, and generating PDF reports. Additionally, it includes scripts for validating service catalog requests, updating the CMDB, and integrating with Jira for high-priority incidents.

Uploaded by

prajaktaraje21
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

1.

Automated Incident Assignment


• Script Type: Business Rule
• Use Case: Automatically assign incidents based on category
(e.g., "Network" → "Network Team").
if ([Link] == 'Network') {
current.assignment_group = 'Network Support';
current.assigned_to = '[Link]@[Link]';
}

2. Dynamic Field Updates


• Script Type: Client Script (OnChange)
• Use Case: Update the Priority field based
on Impact and Urgency.
function onChange(control, oldValue, newValue) {
if (newValue == '1-High') {
g_form.setValue('priority', '1-Critical');
}
}

3. Slack Notifications for Critical Incidents


• Script Type: Notification Script (in Email Notifications)
• Use Case: Send a Slack alert when a P1 Incident is created.
if ([Link] == '1-Critical') {
[Link]('#incidents-channel', 'New P1 Incident: ' +
[Link]);
}

4. Auto-Close Resolved Tasks


• Script Type: Scheduled Job (Background Script)
• Use Case: Close tasks marked as "Resolved" for more than 7
days.
var gr = new GlideRecord('task');
[Link]('state', 'resolved');
[Link]('sys_updated_on', '<=', [Link](7));
[Link]();
while ([Link]()) {
[Link] = 'closed';
[Link]();
}

5. Prevent Duplicate Records


• Script Type: Before Business Rule
• Use Case: Block duplicate Change Requests with the
same Short Description.
var gr = new GlideRecord('change_request');
[Link]('short_description', current.short_description);
[Link]();
if ([Link]()) {
[Link]('Duplicate Change Request!');
[Link](true);
}

6. Auto-Populate User Details


• Script Type: UI Policy Script
• Use Case: When a user is selected, auto-fill
their Department and Location.

var user = new GlideRecord('sys_user');


if ([Link](g_form.getValue('assigned_to'))) {
g_form.setValue('department', [Link]);
g_form.setValue('location', [Link]);
}

7. Generate PDF Reports Automatically


• Script Type: Scheduled Report (via Script Include)
• Use Case: Weekly PDF report of open incidents sent to
managers.
var pdf = new PDFGenerator();
[Link]('incident', 'state=open');
[Link]('managers@[Link]', 'Weekly Open Incidents
Report');

8. Service Catalog Validation


• Script Type: Catalog Client Script
• Use Case: Validate that a requested Laptop Model is in stock.
if (g_form.getValue('laptop_model') == 'MacBook Pro') {
if ([Link]('stock.macbook_pro') <= 0) {
g_form.showErrorBox('laptop_model', 'Out of Stock!');
}
}

9. Automated CMDB Updates


• Script Type: Discovery Schedule Script
• Use Case: Update CI Relationships when new servers are
discovered.

var server = new GlideRecord('cmdb_ci_server');


[Link]('ip_address', discoveryIP);
[Link]();
if (![Link]()) {
[Link]();
[Link] = discoveryHostname;
server.ip_address = discoveryIP;
[Link]();
}

10. Jira-ServiceNow Integration


• Script Type: REST API Script Include
• Use Case: Create a Jira ticket when a High-Priority Incident is
logged.

if ([Link] == '1-Critical') {
var jira = new JiraIntegration();
[Link](
'INC-' + [Link],
current.short_description,
'High'
);
}

You might also like