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.

Advertisements

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
    }
);

Advertisements
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.

Advertisements

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/2019/02/28/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)

Published by

Debajit

I am a Dynamics CRM Most Valuable Professional (MVP) with 12 years of experience in Microsoft .NET Technologies and 9 years of dedicated experience in Microsoft Dynamics CRM. I have worked with companies like Microsoft, SanDisk, PwC, TMF Group and have extensive experience of implementing complex CRM solutions from both offshore and client side. Currently the face of XrmForYou.com with significant experience in delivering corporate training on Dynamics CRM and have already delivered multiple projects to client through XrmForYou.com Author of multiple tools on codeplex including the 'Role Based Views' and 'CRM-Sharepoint Metadata manager & Attachment Extractor' which are available for commercial use under XrmForYou.com For consulting/ training, drop me a note at info@xrmforyou.com or visit our website www.xrmforyou.com

One 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.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s