
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-11-2016 07:01 AM
Anyone have success setting up a custom 2 button push notification for an Incident? I'd like to have a push notification similar to the approval, but with custom buttons for "Assign to Me" and "Ignore".
Push Notification Message Content.
var json = {
"aps" : {
"sound" : "default"
},
"record" : {
"table" : current.getTableName(),
"sys_id" : current.sys_id,
},
"template" : {
"type": "2 button",
"button1" : {
"title" : "Assign to Me",
"action" : attributes.button_action1,
},
"button2" : {
"title" : "Ignore",
"action" : attributes.button_action2,
}
}
};
json;
button_action1
(function runAction(/*Optional GlideRecord*/ current) {
if (current.getTableName() == "incident" && current.assigned_to == undefined) {
current.comments = "I have assigned this incident to myself";
current.assigned_to = gs.getUser();
current.update();
}
})(current);
button_action2
(function runAction(/*Optional GlideRecord*/ current) {
gs.log(gs.getUser() + " ignored this record: " + current.number);
//writes a message to the system log that the user ignored this incident.
})(current);
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2016 09:36 AM
This was the feedback received from Dev task passed up for my HI ticket... two buttons, but they have to be approve and reject and link to the script sys_id that should be taken for the action.
-----------------------
"Wow, I think this documentation is totally inaccurate.
On our apps (iOS and Android), push notifications do not allow custom button titles. The options are "approve"/"reject", and require the aps dictionary to be populated. Here is an example push notification for approvals. The value in approve_foreground and reject_foreground are sys ID's of scripts to run on the server in response to the action."
(function buildJSON(/*GlideRecord*/ current, /*String*/ message, /*Object*/ attributes) {
var json = {};
json = {
"aps" : {
"sound" : "default",
"category" : "approve_reject_foreground"
},
"record" : {
"table" : current.getTableName(),
"sys_id" : current.sys_id
},
"scripts" : {"approve_foreground" : "333ecc6253020200601fa3fc9ec58727",
"reject_foreground" : "632ecc6253020200601fa3fc9ec58708" }
};
return json;
})(current, message, attributes);
-----------------------

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2016 11:16 AM
Thanks for the followup on this Ben. This fell so low on my priority list I pretty much had given up on the possibility of a custom 2 button action on push notifications. It's good to hear the dev say the documentation seems completely inaccurate.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2017 12:26 PM
I thought I'd add that there is a recent Knowledge article describing more detail about sending push notifications to the ServiceNow mobile application.
It currently defines three predefined button pairs (Yes/No, Approve/Reject, Accept/Decline), along with some other information for how you want the app to behave when the push notification is received.
See KB0622333

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2017 12:50 AM
Thanks, Dub d-mile for sharing this KB article - it's a gem.
I finally could accomplish what I needed . Beautiful !
So, for reference: click "view"
push message content:
(function buildJSON(/*GlideRecord*/ current, /*String*/ message, /*Object*/ attributes) {
var json = {};
json = {
"aps": {
"sound":"default",
"category":"accept_decline_background",
},
"record": {
"table":current.getTableName(),
"sys_id":current.sys_id
},
"scripts": {
"accept_background":attributes.btn1_action,
"decline_background":attributes.btn2_action
}
};
return json;
})(current, message, attributes);
Best,
Seb