Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
🛑 Auto-Cancel Playbooks on Incident Deactivation

Script Type: Business Rule (Server-side)
Trigger: before update
Table: incident
Condition: active changes to false

📌 Purpose

Automatically cancel all active Playbooks (sys_pd_context) records associated with an incident when that incident is deactivated (e.g., closed or canceled).

🧠 Logic

- Finds all active playbooks (not in completed,canceled) where:
- input_table is incident (or any other table)
- input_record matches current incident’s sys_id
- Cancels each playbook using: sn_playbook.PlaybookExperience.cancelPlaybook(playbookGR, 'Canceled due to the incident closure or cancellation.');
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
(function executeRule(current, previous /*null when async*/) {

// Find associated playbooks
var playbookGR = new GlideRecord('sys_pd_context');
playbookGR.addQuery('input_table', 'incident');
playbookGR.addQuery('input_record', current.sys_id);
playbookGR.addQuery('state', 'NOT IN', 'completed,canceled');
playbookGR.query();

// Cancel them to avoid hanging context
while (playbookGR.next()) {
sn_playbook.PlaybookExperience.cancelPlaybook(playbookGR, 'Canceled due to the incident closure or cancellation.');
}

})(current, previous);
Loading