Introduction
Imagine logging into Dynamics next time and instantly receiving notifications about crucial events during your absence—leads assigned to you, opportunities closed by your team, and newly opened cases. This is now achievable through 'in-app notifications' for Dynamics 365. Simply activate this feature within your model-driven apps, and users will receive notifications upon login, page navigation, or if they remain on a page for over a minute. Notifications can be registered seamlessly from the front-end, back-end, or via the REST API.
Step 1. Access the maker admin portal at https://make.powerapps.com/ and open the model-driven app where you want to activate this functionality.
Step 2. Select the Moder-driven app and click on the edit button.
Step 3. After clicking on the Setting button, Navigate to Features, and toggle the switch to enable 'In-app notifications'.
Step 4. After enabling in-app notifications, proceed to create a JavaScript web resource containing the following code.
function appNotificationAlert(executionContext) {
// Getting the form context from the execution context
var formContext = executionContext.getFormContext();
// Getting the owner (user) of the contact record
var OwnerId = formContext.getAttribute("ownerid").getValue();
// Extracting the GUID of the owner
var userId = OwnerId[0].id.replace(/{|}/g, '');
// Getting the name of the contact
var contactName = formContext.getAttribute("fullname").getValue();
// Getting the GUID of the contact record
var contactId = formContext.data.entity.getId();
var contactGuid = contactId.replace(/{|}/g, '');
// Creating an object representing the application notification
var inAppNotification = {
title: 'On Contact when name will change', // Title of the notification
body: 'On Contact when name will change Case Number: ' + contactName, // Body of the notification
'[email protected]': '/systemusers(' + userId + ')', // Binding to the owner (user) of the contact
icontype: 100000000, // Icon type for the notification
toasttype: 200000000 // Toast type for the notification
};
// Creating the application notification record using the Xrm.WebApi
Xrm.WebApi.createRecord('appnotification', inAppNotification)
.then((result) => {
console.log('Success registered notification with ID: ' + result.id);
})
.catch((ex) => console.error(`Error message: ${ex.message}`));
}
Icon Type |
Value |
Info |
100000000 |
Success |
100000001 |
Failure |
100000002 |
Warning |
100000003 |
Mention |
100000004 |
Step 5. After creating the web resource, register it for the Contact entity to trigger when the full name field changes.
Usage |
Required table privileges |
The user has no in-app notification bell and receives no in-app notification |
None: Read privilege on the app notification table. |
Users can receive in-app notifications |
Basic: Read privilege on the app notification table. Create, Read, Write, and Append privileges on the model-driven app user setting. Read and AppendTo privileges on setting definition. |
Users can send in-app notifications to self |
Basic: Create and Read privileges on the app notification table, and Send In-App Notification privileges. |
Users can send in-app notifications to others |
Read privilege with Local, Deep, or Global access level on the app notification table based on the receiving user's business unit, and Send In-App Notification privilege. |
Users can delete in-app notifications |
Global: Delete privileges on the app notification table. |
Step 6. Once you update either the first name or last name attribute of the contract, you'll be able to view the application notification.