How to Implement a Push Notification in Power Apps

Introduction

Push notifications are clickable pop-up messages that appear on the user’s device as a way of intimating the user about some information. Messages are sent from the mobile app to the user’s phone screen. To view this notification, the user should have installed the app on the mobile. Thus, push notifications to serve as a quick communication channel to alert the user which he otherwise would get to know only once he navigates to the App.

Graphical user interface, application

Description automatically generated

In this article, we will see how to achieve Push Notifications in the mobile Power App so that we can send notifications to the user’s mobile screen from the app.

Scenario

We will take the Medicine Inventory Demo app where we use it to track incoming medicine stock as well as outgoing medicine requests. In the case of an Outgoing medicine request, some of the medicines like Morphine may fall under the sensitive category, and taking it out of the stock would require an intimation to the medical supervisor. To achieve this, we will provide an option to check if the medicine being taken out belongs to a specific restricted category and if yes, we will be sending a Push Notification to the supervisor while checking out the medicine.

Graphical user interface

Description automatically generated

Implementation

To achieve Push Notifications, we can either invoke Power Automate to use the Power Apps Push Notification action, or else we can add a connection to the Push Notification connector natively in Power App, so as to initiate the Push Notification directly from the Power App. In this sample we will see how to achieve Push Notifications directly from Power App, however, if you have more additional logic that needs to be completed before sending Push Notifications, Power Automate could be a more viable option.

To do this let’s head over to the App from which we want to initiate the Push Notification. From File ->Settings->Support->Session Details- Select the App ID

Graphical user interface, application

Description automatically generated

We can also get the App ID from the Details section of the App from the App List

Graphical user interface, text, application

Description automatically generated

Once we have the App ID, let’s head over to the Data tab in the left pane and create a connection to the Power Apps Notification V2 Connector

Graphical user interface, text, application

Description automatically generated

We will then add the below expression in the Pull Stock button that will save the outgoing stock details to the SharePoint List. We have added the usual patch function to save the data and in addition to that, we have also added a conditional check to see if the Drug belongs to a specific category of drugs. If Yes, we will send the Push Notification to the Supervisor.

Patch(‘Medical Inventory’,{Medicine:TextInput_Medicine.Text,Count:TextInput_Count.Text,Department:TextInput_Department.Text,ScheduleHDrug:Checkbox_ScheduleH.Value});
If(Checkbox_ScheduleH.Value = true,
PowerAppsNotificationV2.SendPushNotificationV2(
“PowerApps”,
“{
appIdentifier:””d904dff7-b5dc-4835-b9ef-d88eac””,
type:””CanvasApp””,
displayName:””””
}”,
Table({Value:”priyan@office365journey.onmicrosoft.com”}),
“A new Schedule H drug (“&TextInput_Medicine.Text&”) has been taken out of the Inventory. For more details, please visit the Medicine Inventory List “,
true,
{}
)
)
Graphical user interface, text

Description automatically generated

The Syntax for Push Notification is as below

Text

Description automatically generated with medium confidence

We have the flexibility to pass parameters to Power App as a key value pair

{StartupScreen:”AdminView”}

When the user clicks on the Notification, it will pass the parameter and open the App. Inside the App, we can consume this value just like we access the Query String using the Param function and Navigate to the corresponding screen.

Param(“StartupScreen”);

Same way, we can pass any specific records the user has to see bypassing the record ID and opening the record using the ID when the user clicks on the Push Notification.

Test the Push Notification

Now let’s test the push notification by previewing the app and adding an outgoing medical record entry

Graphical user interface

Description automatically generated

This has saved the records to the SharePoint List and sent out a Push notification to the user on his/her mobile device

Graphical user interface, text, application, chat or text message

Description automatically generated

Summary

Thus, we saw how to create a Push Notification to a Mobile Device from Power App so as to intimate the user with some app-specific information that will need his attention.

Related Articles

Author

Author

Priyaranjan KS is a Modern Workplace Architect primarily focused on developing and architecting solutions around Office 365,Power Platform and Azure.He is also a Microsoft Most Valuable Professional(MVP) and a Microsoft Certified Trainer(MCT)

Latest Articles