Skip to content

Commit 2c7108f

Browse files
authored
Create README.md
This Flow Designer Custom Action retrieves the current on-call user(s) for a specified assignment group in ServiceNow using the On-Call Scheduling API.
1 parent 1f27921 commit 2c7108f

File tree

1 file changed

+122
-0
lines changed

1 file changed

+122
-0
lines changed

who_is_on_call/README.md

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
README — Get Current On-Call Users (Flow Action)
2+
Purpose:
3+
This Flow Designer Custom Action retrieves the current on-call user(s) for a specified assignment group in ServiceNow using the On-Call Scheduling API.
4+
It can be used in Flows or Subflows to automatically assign incidents, notify escalation contacts, or integrate with messaging systems (Slack, Twilio, etc.).
5+
6+
<img width="1917" height="944" alt="image" src="https://github.com/user-attachments/assets/bbe7fe6a-7418-4c28-9f77-d03dbf64417f" />
7+
8+
9+
🧭 Overview
10+
11+
When triggered, this action:
12+
13+
Looks up the current date/time or a specified timestamp.
14+
15+
Calls global.OnCallRotation().whoIsOnCall() to determine who’s on-call.
16+
17+
Returns a JSON list of all active on-call members (Primary, Secondary, etc.).
18+
19+
Exposes the first on-call member separately for easy assignment or alerting.
20+
21+
⚙️ Inputs
22+
Name Type Required Description
23+
group_sys_id String ✅ Yes The sys_id of the target sys_user_group (e.g., “Major Incident Managers”).
24+
when Date/Time No Optional — specific time to check coverage. Defaults to current time.
25+
📤 Outputs
26+
Name Type Description
27+
users_json String JSON array of on-call user details (sys_id, name, email, phone).
28+
count Integer Total number of users found in the on-call list.
29+
first_user_sys_id String Sys ID of the primary on-call user.
30+
first_user_name String Name of the primary on-call user.
31+
first_user_email String Email address of the primary on-call user.
32+
first_user_phone String Phone number of the primary on-call user.
33+
🧠 Script Logic (Core)
34+
(function execute(inputs, outputs) {
35+
if (!inputs.group_sys_id) {
36+
throw new Error('group_sys_id is required');
37+
}
38+
39+
var rota = new global.OnCallRotation();
40+
var gdt = inputs.when ? new GlideDateTime(inputs.when) : new GlideDateTime();
41+
var list = rota.whoIsOnCall(inputs.group_sys_id + '', '', '', gdt);
42+
43+
var users = [];
44+
if (list && list.length && list.length > 0) {
45+
for (var i = 0; i < list.length; i++) {
46+
var member = list[i];
47+
var userSysId = member.userSysId || member.userId;
48+
49+
if (userSysId) {
50+
var userGR = new GlideRecord('sys_user');
51+
if (userGR.get(userSysId)) {
52+
users.push({
53+
order: i,
54+
sys_id: userGR.getUniqueValue(),
55+
name: userGR.getDisplayValue(),
56+
email: (userGR.email || '').toString(),
57+
phone: (userGR.mobile_phone || userGR.phone || '').toString()
58+
});
59+
}
60+
}
61+
}
62+
}
63+
64+
outputs.users_json = JSON.stringify(users);
65+
outputs.count = users.length;
66+
67+
outputs.first_user_sys_id = users[0] ? users[0].sys_id : '';
68+
outputs.first_user_name = users[0] ? users[0].name : '';
69+
outputs.first_user_email = users[0] ? users[0].email : '';
70+
outputs.first_user_phone = users[0] ? users[0].phone : '';
71+
72+
})(inputs, outputs);
73+
74+
🧩 Usage Example
75+
76+
Flow: “Auto-Assign Major Incident to On-Call Manager”
77+
78+
Trigger: Major Incident Created
79+
80+
Action: Get Current On-Call Users
81+
82+
group_sys_id = e3abf0a8db20b2000ea6fb37bf961969
83+
84+
Condition: count > 0
85+
86+
Set field: Assigned to = ${first_user_sys_id}
87+
88+
Send notification: “Paging ${first_user_name} (on call)”
89+
90+
Else: Fallback to queue or send escalation email.
91+
92+
🧱 Dependencies
93+
94+
Plugin: On-Call Scheduling (com.snc.on_call_rotation)
95+
96+
Tables Accessed:
97+
98+
sys_user
99+
100+
cmn_rota (via API call)
101+
102+
Roles:
103+
104+
admin or any role with read access to On-Call tables.
105+
106+
🧩 Testing
107+
Scenario Expected Result
108+
Group has active on-call rotation Returns 1+ users in users_json
109+
Group has no rotation Returns count = 0
110+
Future when value Returns users scheduled at that time
111+
Invalid group_sys_id Script throws error message
112+
⚠️ Notes & Gotchas
113+
114+
Use global.OnCallRotation(), not SNC.OnCallRotation(), for global scope.
115+
116+
The whoIsOnCall() API returns a JavaScript array, not a GlideRecord list.
117+
118+
The first returned user (index 0) is treated as Primary; subsequent ones are Secondary/Backup.
119+
120+
Ensure on-call rosters are configured with valid coverage windows and active users.
121+
122+
If you want to include future shifts, modify the script to iterate over days with addDaysUTC().

0 commit comments

Comments
 (0)