Push notification example for a custom push app

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

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

Create the push actions

First, 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();
    		current.update();
    	}
    })(current);
  • 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.
    })(current);

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

Create the push content

Next, create the JSON content that specifies two buttons used 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 create attribute definitions for them. But later you override these definitions with the actual button labels and actions on the push message. Here are the definitions:
Figure 1. Attribute definition examples
Examples of push message attribute definitions in the Push Message Attributes Definitions list

Create the push message

Next, 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 created.

Figure 2. Push message example
Example push message for custom app
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 action 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 action 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.

Create the push notification

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

Figure 3. Push notification example
Example push notification containing previously created push message