Here’s a great feature to add a warning/error notification which is scoped globally unlike setFormNotification() which is commonly used and remains within a form itself.
Xrm.App.addGlobalNotification(notificationObject).then(success, error); serves this purpose. Let’s see how –
Disclaimer: Please be aware this is a preview feature yet and I’ll update on this post once this is out of preview.
This is only available for the Unified Interface.
Scenario
Let’s say you have opened an Account form and you want to warn the user in case they are working remotely with someone and might have their screen shared. You want to show a message like this –
And even if they navigate away from the form, it will remain on the screen since it’s scope is global.
Or, user can chose to close it manually which appears at the end of the strip on top-right corner.
You can also optionally add a button and make it navigate to another URL in case you want to share more info with the users (In my example, I redirected to https://www.microsoft.com/en-in/) –
Example
Xrm.App has 2 methods to do the needful –
Xrm.App.addGlobalNotification(notificationObject).then(success, error) & Xrm.App.clearGlobalNotification(notificationObject).then(success, error)
In my scenario, I want to trigger the warning message as soon as the user wanders into one of the Account records. So, in my case, I’ve registered the method onLoad of the Account form itself.
Here’s the code in my JS file for the same –
Some notes before we proceed with the code –
- type in the notification object is supported as 2 at the moment and no other types are supported.
- The levels are as below
- Success
- Error
- Warning
- Information
account = {
globalNotification: function () {var learnMoreAction =
{
actionLabel: “Learn more”,
eventHandler: function () {
Xrm.Navigation.openUrl(“https://microsoft.com”);
}
}
var notificationObj =
{
type: 2,
level: 3, //warning
message: “Please make sure you are not sharing your screen!”,
showCloseButton: true,
action: learnMoreAction
}Xrm.App.addGlobalNotification(notificationObj).then(
function success(result) {
console.log(“Notification created with ID: ” + result);// More code here
},
function (error) {
console.log(error.message);
// handle error here
}
);
}};
I’ve registered the Function as account.globalNotification. You can directly use globalNotification is you are writing function directly as function globalNotification() {}
This notification remains App-wide unless closed by closed by a user of closed using clearGlobalNotification method as mentioned by Microsoft.
Source documentation by Microsoft is here – Xrm.App
Since we are transitioning into Unified Interface, here are some other related posts that you may like looking at –
- D365 Quick Tip: Why BPF wouldn’t appear in D365 Unified Interface?
- Fix Ribbon icons on the Unified Interface in D365 CE
- Change the Unified Interface App Icons
- Unified Interface App URLs – 3 different ways
Hope this helps!!