Want to show a global notification which appears anywhere on your Dynamics 365/ CDS model driven app? Xrm.App.addGlobalNotification does just that. Check this out!

This is one ask which customers had asked for sometime. We have form notifications and field notifications for quite sometime now and this API has also been there for quite sometime. However this is not much used or I shall say rather unknown and through my blog I want to spread the awareness of this wonderful API’s. Trust me, I have even seen experienced CRM consultants coming up and telling this kind of requirement is not possible. But hell yeah! It’s possible.

So let’s see this in action. You can basically use this code from anywhere in Dynamics 365 and it shall work. Below is the code to show a notification where the user have an option to close the notification as well. Not only that, we will also explore to show additional information about the notification. The API has also got a wonderful documentation in Microsoft docs with all the options.

var popupAction =
{
    actionLabel: “Know more”,
    eventHandler: function () {
       // perform other operations as required on clicking
       // you can open up a webresource as well.
       Xrm.Navigation.openWebResource(“<webresourceurl>”);
    }
};

 

// define notification object
var notification =
{
    type: 2,
    level: 4, // information. You can also display warnings/ errors etc.
    message: “This is a sample Notification”,
    action: popupAction
};

 

Xrm.App.addGlobalNotification(notification).then(
    function success(result) {
       sessionStorage.setItem(“GlobalNotificationId”, result);
       // storing it in the session storage will allow you to programmatically close the notifcation at a later point of time
       // using Xrm.App.clearGlobalNotification method.
    },
    function (error) {
       console.log(error.message);
       // handle error conditions
    }
);

image

You can show this up anywhere and this shall be persisted even if you move across various sections in your model driven app. The message won’t however persist if you duplicate tabs or open in new window or refresh the browser altogether. And that’s why I recommend to store the global notification id in sessionSotrage variable so that if it is still not cleared, we can run the code one more to show the notification.

There is very good documentation out there in Microsoft docs as I suggested earlier and I strong recommend going through the options for holistic understanding.

Hope this helps!

Debajit Dutta

(Dynamics MVP)

For consultation/ corporate training visit www.xrmforyou.com or reach out to us at info@xrmforyou.com

Our product offerings:

CRM-Sharepoint Attachment uploader and metadata manager (http://www.xrmforyou.com/sharepoint-integrator.html)

Notes Manager (https://debajmecrm.com/add-metadata-to-your-notes-and-attachments-in-dynamics-notes-metadata-manager-from-xrmforyou-com/)

Role based views for Dynamics 365 (http://www.xrmforyou.com/role-based-views.html)

Record Cloner for Dynamics 365 (http://www.xrmforyou.com/record-cloner.html)

1 thought on “Want to show a global notification which appears anywhere on your Dynamics 365/ CDS model driven app? Xrm.App.addGlobalNotification does just that. Check this out!”

  1. Where do you get these gems from? This is indeed has been a requirement for quite a few clients. Thanks for sharing.

Comments are closed.