In-app notifications within Model-driven apps

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
  • JavaScript - Reusable function definition
  • JavaScript - Usage notification instance
  • In-app notifications implementation steps
  • Managing security for notifications
  • In-app notifications vs. push notifications


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

  • "title": The notification's title.
  • "recipient": The logical name and GUID of the user receiving the notification (e.g., /systemusers(<GUID>)).
  • "body": The main content or message of the notification.
  • "priority": Determines the notification's importance, affecting its display order in the notification center.
  • "iconType": Specifies the icon displayed alongside the notification.
  • "toastType": Defines the notification's behavior, such as whether it appears briefly or remains until dismissed.
  • "expiry": The duration (in seconds) before the notification expires if not dismissed.
  • "overrideContent": Allows customization of the notification's title and body using a limited subset of markdown for styling.
  • "actions": Defines interactive elements within the notification, such as buttons that trigger specific functions or navigation.


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.

Article content
Table 1 - ToastType behavior


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.

Article content
Table 2 - Default in-app notification IconTypes


Read my full article @ https://adevait.com/m365/model-driven-in-app-notifications




To view or add a comment, sign in

Explore topics