Show global notification in model driven app
You know that the function setFormNotification() is used to display a notification message as information, warning or error message on the form and it lives only within the form itself. Once you navigate outside the form, the notification will be gone.
What if, you want to keep the notification across the different areas of the model driven app and not only limited to the form. In order to do this, you can use the function Xrm.App.addGlobalNotification(objNotification).then(success,error) that will not only display a warning, error, or informational/success message, but in addition, it gives the user the possibility to close it and to perform a specific action that will be executed based on the notification.
To implement this, you can register a function on the onLoad of the form or other event handler that will call the below function.
function showGlobalNotification(context) {
var formContext = context.getFormContext();
// define action properties
var objAction =
{
actionLabel: "Click to do something",
eventHandler: function () {
Xrm.Navigation.openUrl("https://docs.microsoft.com/en-us/");
// perform other operations as required on clicking
}
};
// define notification properties
var objNotification =
{
type: 2,
level: 4, // 1: Success, 2: Error, 3: Warning, 4: Information
message: "This is an Information global notification text.",
showCloseButton : true,
action: objAction
};
Xrm.App.addGlobalNotification(objNotification).then(
function success(result) {
// add code on notification display
},
function (error) {
// add code to handle error
}
);
}
The result will be as follows
Below is a summary of the notification properties:
- type: currently only the 2 is supported which displays a notification on the top of the app
- level: number defines the notification level. 1: Success, 2: Error, 3: Warning, 4: Information
- message: the text message that will be displayed in the notification
- showCloseButton: true/false. Defines if the user can close the notification or not
- action: contains 2 properties actionLabel and eventHandler. When defined, a button inside the notification bar will be displayed and once clicked, the code written in the evenHandler property will be executed
You can check this docs link for more details about the global notification.
Bonus Tips:
1. The globalnotification will remain displayed until the user closes it manually or the function Xrm.App.clearGlobalNotification(objNotification).then(success,error) is called
2. Pay attention if on click of the button, you want to accomplish something on the form like setting a field, and since the notification will persist in other areas as well, the form context won't be available in this case, and you have to do additional checking to avoid any error
3. If the action property is set to null, no button will be displayed
4. The showCloseButton property is by default set to false
Hope This Helps!
This was originally posted here.

Like
Report



*This post is locked for comments