Preview: In-App notifications for Model Driven Apps

For this week’s article I am going to discuss a feature that has been in public preview since July 22nd of this year. You are probably wondering what these in-apps notifications for Model Driven Apps are, since we already have the ability to create push notifications using Power Automate. Well, the difference here is that push notifications are only sent to mobile devices, and therefor they won’t be visible for users who access the application through a browser. This new in-app notification feature allows you to create notifications that will show in the browser. I have been waiting for a feature like this for quite some time, so I am very excited to dig in and show you how everything works!

The first thing I want to share is that this is a bit different from ‘regular’ notifications that we’re all used to. What I mean by that is, normally you don’t see an actual record being created when a (push) notification is sent. Well, that’s different with these in-app notifications. If you want to show a notification, you will need to create a row (aka record) in the new ‘notification’ table in Dynamics 365. NOTE: The system name for this table is ‘appnotification’ which is important to know when you’re creating these notifications.
The way it works is that the system will automatically look for rows in the notification table and if notifications are found, they will be shown to the appropriate person. What these notifications look like can be configured.

Before you can start using notifications, you’ll have to enable this feature. Keep in mind this is a preview feature so I wouldn’t recommend doing this in a production environment, so please use a sandbox instance instead. You would need to execute some code in the browser console, which sounds a lot harder than it is! In my example I am going to enable this in my customer service environment using the chrome browser.

Open any sandbox environment and open the app where you want to enable the notification functionality. Once you opened the app, click on the F12 key to open the browser console. Click your mouse next to the blue arrow and enter the following: (image above)

fetch(window.origin + "/api/data/v9.1/SaveSettingValue()", {
method: "POST",
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
AppUniqueName: "customerservicehub",
SettingName: "AllowNotificationsEarlyAccess",
Value: "true"
})
});

4/28/2022 UPDATE: You can now enable these notifications from the app itself. Navigate to https://make.powerapps.com and click on apps on the left hand side. Click on the ellipse next to the app you want to turn in-app notifications on for, then select ‘Edit’ < ‘Edit in preview’ to access the new Power Apps Designer. Click on ‘Settings’ on the top of the designer. Depending on what version you are on, the setting to turn in-app notifications on or off will show under ‘Features’ or ‘Upcoming’. Don’t forget to publish your app!

After you entered the code, make sure to hit enter. Notice that in the script above I entered ‘customerservicehub’ as the app’s unique name. If you want to enable this for your sales app or any of the other apps, you need to use that app’s unique name. You can find the unique app name by opening the app designer and clicking on the properties tab as shown in the image below. If you want to enable this in the sales app you should replace ‘customerservicehub’ in the code above with ‘msdynce_saleshub’.

Once you’ve done this, you will need to publish the app! You can do this again from the app designer. Once you have published the app, the preview is enabled! You should be able to see a bell icon on the top right of the app as shown in the image below.

There are many ways in how we can create these notifications, for example we can use the createRecord API. Microsoft posted some examples here. We can also use the Web API; examples are posted here. Another tool we can use (which I prefer since I am not a developer) is Power Automate. Let’s take a look at how we can configure a flow to automatically create one of those notifications. In this example I am going to create a notification when a new phone call record is created, and I am going to show the notification to the phone call owner. Obviously you can use any trigger in Power Automate flow to create a notification.
Once you log into your Power Automate environment, make sure you have the correct environment selected. You can do this by clicking ‘environments’ on the right of the top bar. Since this is going to be automated logic, we are going to create an automated cloud flow when creating the new flow. Click ‘+New Flow’ on the top left side of the screen and select ‘Automated cloud flow’. In the window that opens click the ‘Skip’ button (I like to use the full window). Make sure you name your flow, for my example I called the flow ‘In-App Notification on new call’.
For the trigger I’m going to use the ‘When a row is added, modified or deleted’. The change type is ‘added’ and the table name is ‘phone calls’. My scope is organization (I want this to run for everyone in the organization) and I am going to run this flow as the modifying user. That’s all you have to enter in the trigger step!

In the next step we’re going to create the actual notification in data verse. Click on ‘+New Step’ and select ‘Add a new row’. For ‘Table name‘ select the ‘Notifications’ table. The rest of this step is really about who the notification goes to and what we want to show in the notification. In the ‘Title‘ field I am going to enter ‘New Phone Call created!!!”. The title field will show in bold in the notification. In the ‘Body‘ field I am going to enter ‘Call regarding’ followed by the dynamic content in the subject field of the phone call that triggered the flow. The data in the ‘Body‘ field will show below the ‘Title‘ field in the notification. The ‘Data‘ field in the step is a JSON structure to provide a more advanced control over the notification. You can leave this field blank if you don’t need rich text formatting, links, and/or custom icons. However, those make for better notifications and would need to be built up using examples shown on Microsoft’s doc site. Since I don’t know how to write JSON I am going to leave this field blank and keep it simple. In the ‘Expiry (seconds)‘ field I will enter the number of seconds after which the notification will be deleted. I am going to set this for 20 minutes, which equals 1200 seconds.

The ‘Icon Type‘ field will allow you to choose an icon to be shown in the notification. There are a few icons you can use out of the box, and it looks like can use a custom icon as well. I haven’t figured out how to do that yet, so I am going to pick the out of the box ‘Success‘ icon. In the ‘Model-driven app‘ field you can set the model-driven app where you want to show the notification. If you leave this field blank the notification will be shown in all apps (if the apps are enabled for notifications). The ‘Owner(Owners)‘ field represents who will see the notification, so I am going to enter the owner value of the trigger here as shown in the screenshot below. Note that I entered /systemusers first and the dynamic content (Owner(value)) in parentheses. Lastly you can set a priority and set the toast type to ‘Timed’. That’s all for the flow configuration! Make sure you save your flow and test it to make sure everything works as expected!
You are probably wondering where you can set how long the notification will pop up in the application? Well, this is a setting that a user can set for themselves by clicking on the bell icon in the application and selecting the gear icon. This will allow users to enable or disable the toast notifications and set the total duration of the notifications.

Once your Power Automate flow runs, you’ll see the toast notification showing up on the screen. I posted an image of what it can look like below. Users can also click on the bell icon (image above) to see all notifications. I do have to mention that it was taking a little while for the notification to show up. I was navigating through the application as this refreshes the browser as I am switching through screens. It looks like the notification is not going to show up if you just sit on the screen waiting for it to show up. I will give this feedback to Microsoft hoping that this can be improved. I hope you enjoyed this article! Be sure to check in again next week for a new article or subscribe here to never miss another post!

Share this!

3 Comments to Preview: In-App notifications for Model Driven Apps