Help with a script for twilio
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-07-2025 07:25 AM
We currently use Twilio which uses a Script Include, Event and Script Action. I am trying to get this to work with Paging Accounts on the Assignment Group vs looking at the On call schedule but I can't figure out how to get it to get those paging accounts. they are on the Group.u_paging_number - u.paging_number_4. Can anyone see anything that jumps out what is wrong with this. TIA
var OnCallScriptIncludePager = Class.create();
OnCallScriptIncludePager.prototype = {
initialize: function() {},
OnCallP2: function(current) {
var groupid = this.getuserssysidfromgroup(current.assignment_group.sys_id.toString());
var pagerlist = [groupid.u_paging_number, groupid.u_paging_number_2, groupid.u_paging_number_3, groupid.u_paging_number_4];
var mobilephone = this.getusermobilephone(pagerlist);
for (var i = 0; i < mobilephone.length; i++) {
SNC.Notify.sendSMS('+16516150611', '' + mobilephone[i], 'P1/P2 Incident Notification: ' + current.number + ':' + current.short_description, current);
}
var result = [current.sys_id.toString(), current.assignment_group.toString()];
gs.eventQueue("OnCallGroupPager", current, result, '1');
var worknotes = "SMS Reminder 1 sent to Incident Group Pagers : " + mobilephone;
this.UpdateINCRecord(current.sys_id, '1', worknotes);
},
//Repeats Sending to All Group Members
onCallP2Repeat: function(result, count) {
gs.sleep(600000);
var response = result.toString().split(',');
var sysid = response[0];
var assignmentGroup = response[1];
var count1 = Number(count) + 1;
var gr1 = new GlideRecord('incident');
gr1.addQuery('sys_id', sysid);
gr1.query();
if (gr1.next()) {
var obj = [gr1.sys_id.toString(), gr1.assignment_group.toString()];
var groupid = this.getuserssysidfromgroup(current.assignment_group.sys_id.toString());
var mobilephone = this.getusermobilephone(groupid.pagerlist);
if (count1 < 4 && !gr1.assigned_to && gr1.priority != '3' && gr1.priority != '4' && assignmentGroup == gr1.assignment_group) {
for (var i = 0; i < mobilephone.length; i++) {
SNC.Notify.sendSMS('+16516150698', '' + mobilephone[i], 'P1/P2 Incident Notification: ' + gr1.number + ':' + gr1.short_description, gr1);
}
gs.eventQueue("OnCallGroupPager", gr1, obj, count1);
var worknotes = "SMS Reminder " + count1 + " sent to Incident Assignment Group Pagers : " + mobilephone;
this.UpdateINCRecord(gr1.sys_id, count1, worknotes);
} else if ((count1 == 4 || count1 < 7) && !gr1.assigned_to && gr1.priority != '3' && gr1.priority != '4' && assignmentGroup == gr1.assignment_group) {
SNC.Notify.sendSMS('+16516150698', '' + gr1.assignment_group.manager.mobile_phone, 'P1/P2 Incident Notification: ' + gr1.number + ':' + gr1.short_description, gr1);
gs.eventQueue("OnCallGroupPager", gr1, obj, count1);
var worknotes = "SMS Reminder " + count1 + " sent to Incident Assignment Group Manager : " + gr1.assignment_group.manager.name;
this.UpdateINCRecord(gr1.sys_id, count1, worknotes);
}
}
},
type: 'OnCallScriptIncludePager'
};
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-07-2025 07:50 AM - edited ‎01-07-2025 07:54 AM
Hi Wendy.
I don't know how you are looking for it but it would be better to make it more modulate in this respect.
OnCallP2: function(current) {
var groupRecord = this.getGroupRecord(current.assignment_group.sys_id.toString());
if (!groupRecord) {
gs.error("Group not found for sys_id: " + current.assignment_group.sys_id);
return;
}
var pagerlist = [
groupRecord.u_paging_number,
groupRecord.u_paging_number_2,
groupRecord.u_paging_number_3,
groupRecord.u_paging_number_4
];
// Get the group Name
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-07-2025 08:03 AM
what's your business requirement here?
Is that an OOB script include?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-07-2025 08:14 AM - edited ‎01-07-2025 08:15 AM
The business requirements are that it pages to the Group.u_paging_number, Group.u_paging_number_1, Group.u_paging_number_2, Group_u_paging_number_3 and Group_u_paging_number_4
If it's a P1/P2 which is controlled by a Business Rule - This script is currently working fine that goes to Group members and then to the On Call Person in a different scenario based on how it's set up but they want the ability to use Service Accounts in place of
var OnCallScriptInclude = Class.create();
OnCallScriptInclude.prototype = {
initialize: function() {},
OnCall: function(current) {
//Sends to On Call Person
var group = current.assignment_group;
var results = this.getmobilephoneofcallperson(group, current.sys_id);
gs.log('results' + results.mobilephone, 'Dallas');
SNC.Notify.sendSMS('+16516150611', results.mobilephone, 'P1/P2 Incident On Call Notification ' + current.number + ':' + current.short_description, current);
var result = [current.sys_id.toString(), current.assignment_group.toString()];
gs.eventQueue("OnCallEvent1", current, result, '1');
var worknotes = "SMS Reminder 1 sent to On Call calendar person : " + results.username;
this.UpdateINCRecord(current.sys_id, '1', worknotes);
},
//Updates Worknotes for On Call Person
UpdateINCRecord: function(sysid, count, worknotes) {
var gr = new GlideRecord('incident');
gr.addQuery('sys_id', sysid);
gr.query();
if (gr.next()) {
gr.work_notes = worknotes;
}
return true;
},
//Repeats Sending to On Call Person
onCallRepeat: function(result, count) {
gs.sleep(600000);
var response = result.toString().split(',');
var sysid = response[0];
var assignmentGroup = response[1];
var count1 = Number(count) + 1;
var worknotes;
var gr1 = new GlideRecord('incident');
gr1.addQuery('sys_id', sysid);
gr1.query();
if (gr1.next()) {
var group = gr1.assignment_group;//Sends to On Call Calender Person
var obj = [gr1.sys_id.toString(), gr1.assignment_group.toString()];
var results = this.getmobilephoneofcallperson(group, gr1.sys_id);
if (count1 < 4 && !gr1.assigned_to && gr1.priority != '3' && gr1.priority != '4' && assignmentGroup == gr1.assignment_group) {
SNC.Notify.sendSMS('+16516150611', '' + results.mobilephone, 'P1/P2 Incident Notification: ' + gr1.number + ':' + gr1.short_description, gr1);
worknotes = "SMS Reminder " + count1 + " sent to On Call Calendar Person : " + results.username;
gs.eventQueue("OnCallEvent1", gr1, obj, count1);
this.UpdateINCRecord(gr1.sys_id, count1, worknotes);
} else if ((count1 == 4 || count1 < 7 ) && !gr1.assigned_to && gr1.priority != '3' && gr1.priority != '4' && assignmentGroup == gr1.assignment_group) {
SNC.Notify.sendSMS('+16516150611', '' + gr1.assignment_group.manager.mobile_phone, 'P1/P2 Incident Notification: ' + gr1.number + ':' + gr1.short_description, gr1);
worknotes = "SMS Reminder " + count1 + " sent to Assignment Group Manager : " + gr1.assignment_group.manager.name;
gs.eventQueue("OnCallEvent1", gr1, obj, count1);
this.UpdateINCRecord(gr1.sys_id, count1, worknotes);
}
}
},
//Updates Worknotes for On Call Person for Repeats
UpdateINCRecord: function(sysid, count, worknotes) {
var gr = new GlideRecord('incident');
gr.addQuery('sys_id', sysid);
gr.query();
if (gr.next()) {
gr.work_notes = worknotes;
gr.update();
}
return true;
},
/////////////////////////////////////////////////////////////////////////////////////
//Sends to ALL Group Members
OnCallToGroupMember: function(current) {
var groupid = this.getuserssysidfromgroup(current.assignment_group);
var mobilephone = this.getusermobilephone(groupid);
var userNames = this.getusernamefromsysid(groupid);
for (var i = 0; i < mobilephone.length; i++) {
SNC.Notify.sendSMS('+16516150611', '' + mobilephone[i], 'P1/P2 Incident Notification: ' + current.number + ':' + current.short_description, current);
}
var result = [current.sys_id.toString(), current.assignment_group.toString()];
gs.eventQueue("OnCallEventGroupMember", current, result, '1');
var worknotes = "SMS Reminder 1 sent to Incident Assignment Group Members : " + userNames;
this.UpdateINCRecord(current.sys_id, '1', worknotes);
},
//Repeats Sending to All Group Members
onCallRepeatGroupMember: function(result, count) {
gs.sleep(600000);
var response = result.toString().split(',');
var sysid = response[0];
var assignmentGroup = response[1];
var count1 = Number(count) + 1;
var gr1 = new GlideRecord('incident');
gr1.addQuery('sys_id', sysid);
gr1.query();
if (gr1.next()) {
var obj = [gr1.sys_id.toString(), gr1.assignment_group.toString()];
var groupid = this.getuserssysidfromgroup(current.assignment_group);
var mobilephone = this.getusermobilephone(groupid);
var userNames = this.getusernamefromsysid(groupid);
if (count1 < 4 && !gr1.assigned_to && gr1.priority != '3' && gr1.priority != '4' && assignmentGroup == gr1.assignment_group) {
for (var i = 0; i < mobilephone.length; i++) {
SNC.Notify.sendSMS('+16516150611', '' + mobilephone[i], 'P1/P2 Incident Notification: ' + gr1.number + ':' + gr1.short_description, gr1);
}
gs.eventQueue("OnCallEventGroupMember", gr1, obj, count1);
var worknotes = "SMS Reminder " + count1 + " sent to Incident Assignment Group Members : " + userNames;
this.UpdateINCRecord(gr1.sys_id, count1, worknotes);
} else if ((count1 == 4 || count1 < 7 ) && !gr1.assigned_to && gr1.priority != '3' && gr1.priority != '4' && assignmentGroup == gr1.assignment_group) {
SNC.Notify.sendSMS('+16516150611', '' + gr1.assignment_group.manager.mobile_phone, 'P1/P2 Incident Notification: ' + gr1.number + ':' + gr1.short_description, gr1);
gs.eventQueue("OnCallEventGroupMember", gr1, obj, count1);
var worknotes = "SMS Reminder " + count1 + " sent to Incident Assignment Group Manager : " + gr1.assignment_group.manager.name;
this.UpdateINCRecord(gr1.sys_id, count1, worknotes);
}
}
},
type: 'OnCallScriptInclude'
};
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-07-2025 08:07 AM
what does this function return? -> getuserssysidfromgroup
Seems it's a JSON or a GlideRecord object and you are getting the key values from it or field values from it
Are you sure the key names or field names are correct?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader