Share via


How to Implement a Push Notification in Power Apps

  • Introduction
  • Scenario
  • Implementation
  • Test the Push Notification
  • Summary

 

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 in the mobile. Thus, push notifications serve as a quick communication channel to alert the user which he otherwise would get to know only once he navigates to the App.

 

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 case of Outgoing medicine request, some of the medicines like Morphine may fall under 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 belong to specific restricted category and if yes, we will be sending a Push Notification to the supervisor while checking out the medicine.

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, lets head over to the App from which we want to initiate the Push Notification. From File ->Settings->Support->Session Details- Select the App ID

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

 

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

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-d88eacd7d56c"",

            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,

        {}

    )

)

The Syntax for Push Notification is as below

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 by passing 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

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

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.