1.
Automatically Escalate Incidents Based on SLA
If an incident's SLA breaches, escalate it to the highest priority.
var gr = new GlideRecord('incident');
[Link]('state', 'IN', '1,2,3'); // New, In Progress, On Hold
[Link]();
while ([Link]()) {
var sla = new GlideSLACalculator('incident', gr.sys_id);
if ([Link]()) {
[Link] = '1'; // Set highest priority
[Link]();
[Link](' Incident ' + [Link] + ' escalated due to SLA breach.');
2. Create a Custom REST API Endpoint
Build a REST API to fetch incident details by number.
var IncidentAPI = [Link]();
[Link] = {
initialize: function() {},
getIncidentByNumber: function(number) {
var gr = new GlideRecord('incident');
[Link]('number', number);
[Link]();
if ([Link]()) {
return {
number: [Link],
short_description: gr.short_description,
state: [Link]()
};
}
return null;
},
type: 'IncidentAPI'
};
3. Update Related Records
Close all tasks related to a specific change request.
var gr = new GlideRecord('task');
[Link]('change_request.number', 'CHG0010001');
[Link]();
while ([Link]()) {
[Link] = '3'; // Closed
[Link]();
[Link](' Task ' + [Link] + ' closed for change request CHG0010001.');
4. Check User Roles
Verify if the user has a specific role before proceeding.
if ([Link]('itil')) {
[Link](' User has ITIL role.');
} else {
[Link](' User does not have ITIL role.');
5. Perform Bulk Updates
Update the assignment group for all incidents assigned to a specific user.
var gr = new GlideRecord('incident');
[Link]('assigned_to', 'user_sys_id');
[Link]();
while ([Link]()) {
gr.assignment_group = 'New Group';
[Link]();
[Link](' Incident ' + [Link] + ' updated.');
6. Delete Old Incidents
Remove incidents older than 90 days.
var gr = new GlideRecord('incident');
[Link]('sys_created_on', '<=', [Link](90));
[Link]();
while ([Link]()) {
[Link]();
[Link](' Deleted incident: ' + [Link]);
7. Log Active Incident Data
Print details of all active incidents.
var gr = new GlideRecord('incident');
[Link]('active', true);
[Link]();
while ([Link]()) {
[Link](' Incident ' + [Link] + ': ' + gr.short_description);
8. Create Related Problem Records
Generate a problem record for incidents with specific short descriptions.
var gr = new GlideRecord('incident');
[Link]('short_description', 'CONTAINS', 'outage');
[Link]();
while ([Link]()) {
var problem = new GlideRecord('problem');
[Link]();
problem.short_description = 'Problem for incident: ' + [Link];
[Link] = 'Related incident: ' + gr.short_description;
[Link]();
[Link](' Problem created for incident: ' + [Link]);