In-app notifications within Model-driven apps
The target audience for this article are Power Platform Developers and Solution Architects with some understanding or familiarity with JavaScript or coding. That said, coding is beyond the scope of the article. Now that article's scope has been outlined, let's get to it.
In this article, you will learn about:
Model-driven in-app notifications
"Model-driven" apps allow developers to configure in-app notifications as toast messages within the notification centre. The system automatically checks for new notifications and displays them accordingly. The sender or an administrator can control how notifications appear and when they expire (default is 14 days, but this can be overridden).
Notifications are user-specific, meaning each is sent to an individual user and not to teams. To notify multiple users, separate notifications must be created for each. This article provides steps for sending in-app notifications to a specific user.
JavaScript - Reusable function definition
The function, "InAppNotificationWrapper.SendAppNotificationRequest", streamlines the process of generating and dispatching notifications by encapsulating the necessary parameters and metadata. You should define the "InAppNotificationWrapper.SendAppNotificationRequest" reusable function in a standalone JavaScript file. The function is defined as follows:
// define SendAppNotificationRequest function
var InAppNotificationWrapper = window.InAppNotificationWrapper || {};
InAppNotificationWrapper.SendAppNotificationRequest = function (
title,
recipient,
body,
priority,
iconType,
toastType,
expiry,
overrideContent,
actions)
{
this.Title = title;
this.Recipient = recipient;
this.Body = body;
this.Priority = priority;
this.IconType = iconType;
this.ToastType = toastType;
this.Expiry = expiry;
this.OverrideContent = overrideContent;
this.Actions = actions;
};
InAppNotificationWrapper.SendAppNotificationRequest.prototype.getMetadata = function () {
return {
boundParameter: null,
parameterTypes: {
"Title": {
"typeName": "Edm.String",
"structuralProperty": 1
},
"Recipient": {
"typeName": "mscrm.systemuser",
"structuralProperty": 5
},
"Body": {
"typeName": "Edm.String",
"structuralProperty": 1
},
"Priority": {
"typeName": "Edm.Int",
"structuralProperty": 1
},
"IconType": {
"typeName": "Edm.Int",
"structuralProperty": 1
},
"ToastType": {
"typeName": "Edm.Int",
"structuralProperty": 1
},
"Expiry": {
"typeName": "Edm.Int",
"structuralProperty": 1
},
"OverrideContent": {
"typeName": "mscrm.expando",
"structuralProperty": 5
},
"Actions": {
"typeName": "mscrm.expando",
"structuralProperty": 5
},
},
operationType: 0,
operationName: "SendAppNotification",
};
};
Code 1 - define SendAppNotificationRequest function
Notifications sent using the "SendAppNotification" message are stored in the notification (appnotification) table (Web API appnotification). The full table can be found @ appnotification EntityType (Microsoft.Dynamics.CRM) | Microsoft Learn.
Script parameters
Notification behavior
You can change in-app notification behaviour by setting "toastType" to one of the following values as per below in Table 1 - ToastType behaviour.
Notification icons
You can change the default in-app notification icon by setting "iconType" to one of the following values in Table 2. When using a custom icon, specify the "iconUrl" parameter within the OverrideContent parameter.
Read my full article @ https://adevait.com/m365/model-driven-in-app-notifications