显示应用的错误、信息、警告或成功通知,并允许你根据通知指定要执行的作。
Syntax
Xrm.App.addGlobalNotification(notification).then(successCallback, errorCallback);
参数
| Name | 类型 | 必选 | Description |
|---|---|---|---|
notification |
物体 | 是的 | 要添加的通知。 请参阅 通知参数 |
successCallback |
功能 | 否 | 显示通知时要调用的函数。 GUID 值将传递给唯一标识通知。 可以使用 GUID 值通过 clearGlobalNotification 方法关闭或关闭通知。 |
errorCallback |
功能 | 否 | 作失败时要调用的函数。 |
notification 属性
该对象包含以下属性:
| 资产 | 类型 | 必选 | Description |
|---|---|---|---|
action |
物体 | 否 | 具有以下属性的对象: - actionLabel(可选)字符串。 邮件中作的标签。- eventHandler:(可选)函数引用。 单击作标签时要执行的函数。 |
level |
编号 | 是的 | 定义通知级别。 有效值为: 1:成功 2:错误 3:警告 4:信息 |
message |
String | 是的 | 通知中显示的消息。 |
showCloseButton |
布尔值 | 否 | 指示用户是否可以关闭或关闭通知。 如果未指定此参数,则默认情况下用户无法关闭或关闭通知。 |
type |
编号 | 是的 | 定义通知的类型。 目前,仅支持值 2,它显示应用顶部的消息栏。 |
返回值
成功后,返回包含 GUID 值的 promise 对象,以唯一标识通知,如 successCallback 参数的说明前面所述。
例子
显示用户无法关闭或关闭的错误通知
// define notification object
var notification =
{
type: 2,
level: 2, //error
message: "Test error notification"
}
Xrm.App.addGlobalNotification(notification).then(
function success(result) {
console.log("Notification created with ID: " + result);
// perform other operations as required on notification display
},
function (error) {
console.log(error.message);
// handle error conditions
}
);
这是错误通知在应用中的显示方式:
显示可由用户关闭或关闭的警告通知
// define notification object
var notification =
{
type: 2,
level: 3, //warning
message: "Test warning notification",
showCloseButton: true
}
Xrm.App.addGlobalNotification(notification).then(
function success(result) {
console.log("Notification created with ID: " + result);
// perform other operations as required on notification display
},
function (error) {
console.log(error.message);
// handle error conditions
}
);
这是警告通知在应用中的显示方式:
显示信息通知,其中包含用户可单击的“了解详细信息”链接
// define action object
var myAction =
{
actionLabel: "Learn more",
eventHandler: function () {
Xrm.Navigation.openUrl("https://free.blessedness.top/powerapps/");
// perform other operations as required on clicking
}
}
// define notification object
var notification =
{
type: 2,
level: 4, // information
message: "Test information notification",
action: myAction
}
Xrm.App.addGlobalNotification(notification).then(
function success(result) {
console.log("Notification created with ID: " + result);
// perform other operations as required on notification display
},
function (error) {
console.log(error.message);
// handle error conditions
}
);
这是信息通知在应用中的显示方式: