1010 views

ServiceNow Mobile App Push Notifications

Overview

This discussion applies to the ServiceNow native mobile apps for iOS and Android. For information on integrating notifications with a custom mobile application, please see Setup Push Notifications for a Custom Push App.

Push notification payloads sent from an instance to the ServiceNow mobile apps support the following attributes:

  • Message: The message text to display in the notification alert.
  • Notification category: An optional category used to determine which predefined actions (buttons) should be displayed and whether the mobile app should be opened in response to an action.
  • Scripts: The script to run when a specific button is tapped. Scripts are stored in the sys_push_notif_act_script table.
  • Record: An optional record to open in response to the notification.
  • Web Path: An optional web path or URL to open in response to the notification. This takes precedence over the record attribute.

Supported Categories

A notification category is used to determine which predefined actions (buttons) should be displayed and whether the mobile app should be opened in response to an action.

Note: Custom button titles are not supported by the ServiceNow mobile apps. A notification category is the only way to specify predefined button titles. Notification categories are not stored on the instance and can not be modified.

The ServiceNow mobile apps support the following categories:

Category IdentifierButton 1 TitleButton 1 IdentifierButton 1 ModeButton 2 TitleButton 2 IdentifierButton 2 Mode
approve_reject_foregroundApproveapprove_foregroundforegroundRejectreject_foregroundforeground
approve_reject_backgroundApproveapprove_backgroundbackgroundRejectreject_backgroundbackground
yes_no_foregroundYesyes_foregroundforegroundNono_foregroundforeground
yes_no_backgroundYesyes_backgroundbackgroundNono_backgroundbackground
accept_decline_foregroundAcceptaccept_foregroundforegroundDeclinedecline_foregroundforeground
accept_decline_backgroundAcceptaccept_backgroundbackgroundDeclinedecline_backgroundbackground

Generating Payloads

Push Notification Message Content records are stored in the sys_push_notif_msg_content table. These records are used to generate push notification payloads. Below are example scripts that demonstrate how to generate payloads with different behavior and buttons.

Record Payload

This payload will open the app to the current record when the notification is opened. The notification will not have any buttons.

(function buildJSON(/*GlideRecord*/ current, /*String*/ message, /*Object*/ attributes) {

    var json = {};

    json = {
        "aps" : {
            "sound" : "default"
        },
        "record" : {
            "table" : current.getTableName(),
            "sys_id" : current.sys_id
        }
    };

    return json;

})(current, message, attributes);

Web Path Payload

This payload will open the app to a custom web path or URL when the notification is opened. The notification will not have any buttons.

(function buildJSON(/*GlideRecord*/ current, /*String*/ message, /*Object*/ attributes) {

    var json = {};

    json = {
        "aps" : {
            "sound" : "default"
        },
        "web_path" : "$vtb.do"
    };

    return json;

})(current, message, attributes);

Approve / Reject Foreground Payload

This payload will open the app to the current record when the notification is opened or a button is tapped. The notification will have "Approve" and "Reject" buttons that will trigger a script in the foreground and cause the app to open.

(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);

Yes / No Background Payload

This payload will open the app to the current record when the notification is opened, but not when a button is tapped. The notification will have "Yes" and "No" buttons that will trigger a script in the background without opening the app.

(function buildJSON(/*GlideRecord*/ current, /*String*/ message, /*Object*/ attributes) {

    var json = {};

    json = {
        "aps" : {
            "sound" : "default",
            "category" : "yes_no_background"
        },
        "record" : {
            "table" : current.getTableName(),
            "sys_id" : current.sys_id
        },
        "scripts" : {"yes_background" : "333ecc6253020200601fa3fc9ec58727",
                     "no_background" : "632ecc6253020200601fa3fc9ec58708" }
    };

    return json;

})(current, message, attributes);

Article Information

Last Updated:2017-10-25 19:26:38
Published:2017-04-18