Notify a Task is complete inside your Model-Driven App

Shows the Notification inside a Model-Driven App and Highlights where you can find the In-App Notifications

When assigning critical Tasks to different users or teams, you probably want to know when they have finished them! You probably also do not want a mobile push notification disturbing you in your work. Luckily Model-Driven Apps provide a way to notify users! In this post I show you how to accomplish this using Power Automate and the In-App Notification center of Model-Driven Apps.

The In-App Notification center, when enabled, lets users see and manage all their notifications. This can be all sorts of notification, all of which you can create! You do this using either JavaScript, C# or Power Automate by creating a record in the Notifications table. The columns in this table allow you to declare for example the title of the notification, the owner who is going to receive the notification and the IconType which shows along with the notification.

But what I find really cool, is that you can create a richer card for your notification. You do so by combining the body and data column of the notification table. In the body you can use some Markdown to style your message. In the data column we can add json to add actions in the notifications. Actions allow you to add navigation urls to for example a form in your app. Building these is a breeze with the In-App Notification Builder in the XrmToolBox.

Following up on a task

This blogpost builds upon my previous blog post in which I show how to notify a user by posting an Adaptive Card to teams. It is part of a case where a customer wants a new screen for his broken phone. The user who sends the screen does not use our Model-Driven App often, but when he completes the task, we do want to be notified!

First things first, we need to enable our application for In-App notifications. This we have to do inside the App Designer of the Model-Driven application. Go to settings and under the Features tab you can find the setting.

Shows where to find the In-app notifications setting. It is in the Model-App desiger settings under the tab Features.
Enable In-app Notifications Setting

Now let’s open the In-App Notification Builder and get cooking. For the Title of the Notification, we set “Task Completed”. If you want a more expressive name, you can of course change this in the Power Automate formula. The body is a simple text explaining that the Task is **completed**. Use the Bold button to help you write Markdown in your Body text. The Markdown notation for Bold are the stars around “completed”.

The Toast Type lets you select if the notification should show immediately on the form if the User is already in our app. If you choose hidden, it will only appear in the notification center. For this Notification I choose the Info icon, but you can choose others, or even select a webresource for a custom Icon. For reference below is the complete notification that we are going to build. Do check out the Preview feature in this screenshot, this is also how it will look inside our app!

Shows the complete In-App Notification Builder. On the right a preview of the Notification that is built on the left.
In-App Notification Builder Complete

Create the Actions and get the code

Now that we have the basics covered, we want to add 2 actions to easily navigate to the relevant records. One to go the Case and one to go to the Task. Add these by using the actions in the bottom of the tool. We can define the text of the action and if it needs to open inline, as a dialog or in a new window. The tool also lets you define specific types like URL, Form or Custom Page. But in the end, they will all generate a URL. I prefer to just build the URL in Power Automate, but it can help you build your URL. Keep in mind that some parts are hardcoded and will need changing for other environments.

Shows the Create Action Modal in the XrmToolBox tool In-App notification builder.
Create Action

Now that we’ve build the Notification we can go ahead and generate the code for it. The In-App Notification Builder has a button to do just that. In our example we want to use it in Power Automate, but you can choose C# or JavaScript if that fits your use case. The code for Power Automate is a nice overview what property needs to be filled in the Notification table. We just have to change certain properties with variables from Power Automate.

Shows the In-App Notification Builder. Highlighting the Power Automate button to get the code of your Notification.
Get Power Automate Code of the Notification
Shows the generated code from the In-App Notification Builder which can be copied to Power Automate
Generated Power Automate Code

Prepare in Power Automate

Let’s go to our flow! As mentioned in the introduction I am extending a flow of my previous blogpost. When a Task is created, we send an Adaptive Card to a Teams user. When that user indicates the Task is complete, the Flow continues, and we want to notify the owner of the Case the Task is related to.

First, start with building the URLs for the 2 actions in our notification. The “Create the task record URL “is already there as that is also inside the Adaptive Card. We create a second compose for the case record URL. To dynamically grab the environment URL of the Model-App I use a combination of the “OData Id” URL and the uriHost() function. The uriHost will grab the “base” part of the URL, so we can extend upon it. See this other blogpost where I explain this in a little bit more depth.

Shows Power Automate actions to create Urls to the case and task records which we will use in the Notification
Create Urls

Now we can use these Compose variables to inject into the Data part of the Notification. I like to use another Compose action for this, as this will help me stay organized. Copy and paste the code from the In-App Notification Builder into the compose action and change the google.com URLs to the corresponding output of the Composes above.

Shows a Power Automate Action Compose where dynamic data is added to the Notification Data
Compose Notification Data

Create the In-App Notification

Now it’s time to create the actual Notifications record in Dataverse. Again, copy and paste the information from the Notification Builder and we are almost done! The only part we need to change is the Owner of the Notification record. the Guid placeholder we change to the owner of the case. This is part of a Lookup field, so we pick the actual value where the Guid is stored.

Shows a Power Automate action where a record is added to the Notification Table.
Add a new Notification Record

That’s it! You can now test the Cloud Flow and a nice Notification with actions will appear in your Model-Driven Power App.

Shows the Notification inside a Model-Driven App and Highlights where you can find the In-App Notifications
Finished Notification

I think it’s neat that we have all these features we can use in the Power Platform. This is definitely a productivity hack for the users of your App. You only have to make sure to do this consistently. If a user expects to be notified that Tasks are finished, they might not check the actual record anymore 😉

Leave a Reply

Your email address will not be published. Required fields are marked *