|
| 1 | +--- |
| 2 | +title: "addGlobalNotification (Client API reference) in model-driven apps| MicrosoftDocs" |
| 3 | +ms.date: 03/09/2020 |
| 4 | +ms.service: powerapps |
| 5 | +ms.topic: "reference" |
| 6 | +author: "KumarVivek" |
| 7 | +ms.author: "kvivek" |
| 8 | +manager: "annbe" |
| 9 | +search.audienceType: |
| 10 | + - developer |
| 11 | +search.app: |
| 12 | + - PowerApps |
| 13 | +--- |
| 14 | +# addGlobalNotification (Client API reference) |
| 15 | + |
| 16 | +[This topic is pre-release documentation and is subject to change.] |
| 17 | + |
| 18 | +[!INCLUDE[./includes/addGlobalNotification-description.md](./includes/addGlobalNotification-description.md)] |
| 19 | + |
| 20 | +> [!NOTE] |
| 21 | +> This is a preview feature, and is supported only on Unified Interface. |
| 22 | +
|
| 23 | +## Syntax |
| 24 | + |
| 25 | +`Xrm.App.addGlobalNotification(notification).then(successCallback, errorCallback);` |
| 26 | + |
| 27 | +## Parameters |
| 28 | + |
| 29 | +<table style="width:100%"> |
| 30 | +<tr> |
| 31 | +<th>Name</th> |
| 32 | +<th>Type</th> |
| 33 | +<th>Required</th> |
| 34 | +<th>Description</th> |
| 35 | +</tr> |
| 36 | +<tr> |
| 37 | +<td>notification</td> |
| 38 | +<td>Object</td> |
| 39 | +<td>Yes</td> |
| 40 | +<td>The notification to add. The object contains the following attributes: |
| 41 | +<ul> |
| 42 | +<li><b>action</b>: (Optional) Object. Contains the following attributes: |
| 43 | +<ul> |
| 44 | +<li><b>actionLabel</b>: (Optional) String. The label for the action in the message.</li> |
| 45 | +<li><b>eventHandler</b>: (Optional) Function reference. The function to execute when the action label is clicked.</li> |
| 46 | +</ul> |
| 47 | +<li><b>level</b>: Number. Defines the level of notification. Valid values are: |
| 48 | +<ul><li>1: Success</li> |
| 49 | +<li>2: Error</li> |
| 50 | +<li>3: Warning</li> |
| 51 | +<li>4: Information</li></ul></li> |
| 52 | +<li><b>message</b>: String. The message to display in the notification.</li> |
| 53 | +<li><b>showCloseButton</b>: (Optional) Boolean. Indicates whether or not the user can close or dismiss the notification. If you don't specify this parameter, users can't close or dismiss the notification by default.</li> |
| 54 | +<li><b>type</b>: Number. Defines the type of notification. Currently, only a value of 2 is supported, which displays a message bar at the top of the app.</li> |
| 55 | +</ul></td> |
| 56 | +</tr> |
| 57 | +<tr> |
| 58 | +<td>successCallback</td> |
| 59 | +<td>Function</td> |
| 60 | +<td>No</td> |
| 61 | +<td><p>A function to call when notification is displayed. A GUID value is passed to uniquely identify the notification. You can use the GUID value to close or dismiss the notification using the <a href="clearGlobalNotification.md">clearGlobalNotification</a> method.</p> |
| 62 | +</td> |
| 63 | +</tr> |
| 64 | +<tr> |
| 65 | +<td>errorCallback</td> |
| 66 | +<td>Function</td> |
| 67 | +<td>No</td> |
| 68 | +<td>A function to call when the operation fails.</td> |
| 69 | +</tr> |
| 70 | +</table> |
| 71 | + |
| 72 | +## Return Value |
| 73 | + |
| 74 | +On success, returns a promise object containing a GUID value to uniquely identify the notification as described earlier in the description of the **successCallback** parameter. |
| 75 | + |
| 76 | +## Examples |
| 77 | + |
| 78 | +### Display an error notification that can't be closed or dismissed by user |
| 79 | + |
| 80 | +```JavaScript |
| 81 | +// define notification object |
| 82 | +var notification = |
| 83 | +{ |
| 84 | + type: 2, |
| 85 | + level: 2, //error |
| 86 | + message: "Test error notification" |
| 87 | +} |
| 88 | + |
| 89 | +Xrm.App.addGlobalNotification(notification).then( |
| 90 | + function success(result) { |
| 91 | + console.log("Notification created with ID: " + result); |
| 92 | + // perform other operations as required on notification display |
| 93 | + }, |
| 94 | + function (error) { |
| 95 | + console.log(error.message); |
| 96 | + // handle error conditions |
| 97 | + } |
| 98 | +); |
| 99 | +``` |
| 100 | + |
| 101 | +This is how the error notification will appear in the app: |
| 102 | + |
| 103 | + |
| 104 | + |
| 105 | +### Display a warning notification that can be closed or dismissed by user |
| 106 | + |
| 107 | +```JavaScript |
| 108 | +// define notification object |
| 109 | +var notification = |
| 110 | +{ |
| 111 | + type: 2, |
| 112 | + level: 3, //warning |
| 113 | + message: "Test warning notification", |
| 114 | + showCloseButton: true |
| 115 | +} |
| 116 | + |
| 117 | +Xrm.App.addGlobalNotification(notification).then( |
| 118 | + function success(result) { |
| 119 | + console.log("Notification created with ID: " + result); |
| 120 | + // perform other operations as required on notification display |
| 121 | + }, |
| 122 | + function (error) { |
| 123 | + console.log(error.message); |
| 124 | + // handle error conditions |
| 125 | + } |
| 126 | +); |
| 127 | +``` |
| 128 | + |
| 129 | +This is how the warning notification will appear in the app: |
| 130 | + |
| 131 | + |
| 132 | + |
| 133 | +### Display an information notification with a "Learn more" link that can be clicked by users |
| 134 | + |
| 135 | +```javascript |
| 136 | +// define action object |
| 137 | +var myAction = |
| 138 | +{ |
| 139 | + actionLabel: "Learn more", |
| 140 | + eventHandler: function () { |
| 141 | + Xrm.Navigation.openUrl("https://docs.microsoft.com/powerapps/"); |
| 142 | + // perform other operations as required on clicking |
| 143 | + } |
| 144 | +} |
| 145 | + |
| 146 | +// define notification object |
| 147 | +var notification = |
| 148 | +{ |
| 149 | + type: 2, |
| 150 | + level: 4, // information |
| 151 | + message: "Test information notification", |
| 152 | + action: myAction |
| 153 | +} |
| 154 | + |
| 155 | +Xrm.App.addGlobalNotification(notification).then( |
| 156 | + function success(result) { |
| 157 | + console.log("Notification created with ID: " + result); |
| 158 | + // perform other operations as required on notification display |
| 159 | + }, |
| 160 | + function (error) { |
| 161 | + console.log(error.message); |
| 162 | + // handle error conditions |
| 163 | + } |
| 164 | +); |
| 165 | +``` |
| 166 | + |
| 167 | +This is how the information notification will appear in the app: |
| 168 | + |
| 169 | + |
| 170 | + |
| 171 | +### See also |
| 172 | + |
| 173 | +[clearGlobalNotification](clearGlobalnotification.md) |
0 commit comments