Thank you for your feedback.
Form temporarily unavailable. Please try again or contact to submit your comments.

Push notification example

Log in to subscribe to topics and get notified when content changes.

Push notification example

This example illustrates a customized push notification, including customized push actions and content.

In this example, you will learn how to create a push notification for incidents that are not assigned to anyone. This example assumes you created your own custom push application that is referred to in this example as MyPushApp. The notification will be sent to a user who can respond by accepting assignment to the incident or ignoring it.

The push actions

First you will create push actions that give the user options on how to respond to the push notification. In this example, create two actions: assign to me and ignore. The content of the actions is as follows:

  • Assign to me:
    (function runAction(/*Optional GlideRecord*/ current) {
    	if (current.getTableName() == "incident" && current.assigned_to == undefined) {
    		current.comments = "I have self assigned this incident to myself";
    		current.assigned_to = gs.getUser();
  • Ignore:
    (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.

See Create a push action for specific steps on how to create these actions.

The push content

Next, you will create the JSON content that specifies two buttons that the user will use to respond to the incident. The content is as follows:

(function buildJSON(/*GlideRecord*/ current, /*String*/ message, /*Object*/ attributes) {
	var json = {};
	json = {
		"aps" : {
			"sound" : "default"
		"record" : {
			"table" : current.getTableName(),
			"sys_id" : current.sys_id
		"action" : {
                                "button1_text" : attributes.name_of_button1,
				    "button1_action" : attributes.action_of_button1,
				    "button2_text" : attributes.name_of_button2,
				    "button2_action" : attributes.action_of_button2 }
	return json;	
})(current, message, attributes);
The content script specifies two labels and two actions, one for each button. You must create definitions for these. But later you will override these definitions with the actual button labels and actions on the push message. Here are the definitions:
Figure 1. Attribute definition examples

The push message

Next you will create a push message that specifies the message that appears to the user: Can you take on a new incident?. The push message associates your custom application MyPushApp with the content you just created.

Figure 2. Push message example
The Push Message Attribute Values related list specifies the four items needed for the button label and the action the instance takes when the user clicks that button:
Table 1. Push message attribute values
Attribute Value Action Description
action_on_button2 Ignore

The value is ignored because this attribute specifies an action.

Ignore The Ignore action is what you specified as a push action. This is associated with button 2.
action_on_button1 Assign to me

The value is ignored because this attribute specifies an action.

Assign to me The Assign to me action is what you specified as a push action. This is associated with button 1.
name_of_button2 Ignore none Ignore is the label the user sees for button 2.
name_of_button1 Assign to me none Assign to me is the label the user sees for button 1.

The push notification

Finally, you will create a notification that is triggered when a new incident is unassigned. It is sent to a group named Incident Manager. You will then associate the push message that you just created with it. The notification is as follows:

Figure 3. Push notification example