Follow my blog for more interesting topics on Dynamics 365, Portals and Power Platform. For training and consulting, write to us at info@xrmforyou.com
For a long time this has been the ask by so many customers. Show a notification message bar on a Dashboard. Very similar to the application message you see on the Application message bar on your mailbox configuration page or Sharepoint configuration page.
For a very long time, Microsoft didn’t provide any API’s to show a notification like this except on entity form where you can use setFormNotification to show similar notification on entity forms.
Well the wait is over. Microsoft have indeed released the API to show global notifications anywhere in your application. The API is – Xrm.App.addGlobalNotification(notification)
I have written a blog on this topic sometime back which is more of like Generic introduction to the API. Post that I got request to show the notification on Dashboard. And here I am back with a blog on reader request.
The first thing is we will insert a button on the Dashboard. As you already know, you need to modify the application ribbon to insert a button on Dashboard page.
- I insert a button on Dashboard page – ‘Dashboard Button’.
- I create an enable rule for the custom button.
Below is the code in function defined for enable rule.
var popupAction = { actionLabel: "Click to open privacy page.", eventHandler: function () { // perform other operations as required on clicking // you can open up a webresource as well. Xrm.Navigation.openWebResource("cr947_/pages/privacy.html"); } }; // define notification object var notification = { type: 2, level: 4, // information. 1. success, 2. error, 3. warning message: "You need to accept terms and conditions. Visit our policy page.", action: popupAction }; function NotificationRule() { // function called on Enable rule Xrm.App.addGlobalNotification(notification).then( function success(result) { sessionStorage.setItem("notification_terms_privacy", 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 } ); return false; }
Observe I am always returning false in the enable rule function. The reason for this is my intention is just to execute some script here to show the notification. The button is merely a placeholder to execute my script and hence I don’t want to show it on the screen.
And now when the dashboard load, I can see the notification right up there. If I click on the “Click to open privacy page”, I can see the privacy page showing up.
Wonderful isn’t it? You can use Xrm.Navigation.navigateTo instead of Xrm.Navigation.openWebResource to show the page as modal.
Hope this helps!
Debajit Dutta
(Business Solutions MVP)
Discover more from Debajit's Power Apps & Dynamics 365 Blog
Subscribe to get the latest posts sent to your email.