Skip to content

Commit f35b2a6

Browse files
authored
Cancel Incomplete Playbooks on Closure (#2005)
* Catalog Item Explorer - Widget Update Functionality update: - Support for the external URL content items. - The default target window changed to "_self" (same window). - Option to open an item in a new window added at the end of the row. * Update css.scss * Update script.js * Update client_script.js * Update options_schema.json * Create script.js * Create README.md
1 parent 3d12a1f commit f35b2a6

File tree

2 files changed

+32
-0
lines changed
  • Server-Side Components/Business Rules/Cancel Incomplete Playbooks on Closure

2 files changed

+32
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
🛑 Auto-Cancel Playbooks on Incident Deactivation
2+
3+
Script Type: Business Rule (Server-side)
4+
Trigger: before update
5+
Table: incident
6+
Condition: active changes to false
7+
8+
📌 Purpose
9+
10+
Automatically cancel all active Playbooks (sys_pd_context) records associated with an incident when that incident is deactivated (e.g., closed or canceled).
11+
12+
🧠 Logic
13+
14+
- Finds all active playbooks (not in completed,canceled) where:
15+
- input_table is incident (or any other table)
16+
- input_record matches current incident’s sys_id
17+
- Cancels each playbook using: sn_playbook.PlaybookExperience.cancelPlaybook(playbookGR, 'Canceled due to the incident closure or cancellation.');
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
(function executeRule(current, previous /*null when async*/) {
2+
3+
// Find associated playbooks
4+
var playbookGR = new GlideRecord('sys_pd_context');
5+
playbookGR.addQuery('input_table', 'incident');
6+
playbookGR.addQuery('input_record', current.sys_id);
7+
playbookGR.addQuery('state', 'NOT IN', 'completed,canceled');
8+
playbookGR.query();
9+
10+
// Cancel them to avoid hanging context
11+
while (playbookGR.next()) {
12+
sn_playbook.PlaybookExperience.cancelPlaybook(playbookGR, 'Canceled due to the incident closure or cancellation.');
13+
}
14+
15+
})(current, previous);

0 commit comments

Comments
 (0)