我想在发送电子邮件时显示警告消息。并且仅在用户单击关闭后发送。 我在notificationMessages上将persistent设置为true。 但是,在发送电子邮件时,将迅速显示该消息,但是将立即发送该电子邮件,而我没有机会阅读该消息。
任何想法我该怎么办?
Office.context.mailbox.item.notificationMessages.addAsync("cost_warning", {
type: "informationalMessage",
message: "message",
icon : "iconid",
persistent: true
});
event.completed({ allowEvent: true });
答案 0 :(得分:0)
您可以使用NotificationMessage.getAllAsync API来实现。
只需使用setInterval设置一个间隔,然后等到notificationMessage.getAllAsync()停止返回您的通知,然后调用
event.completed({ allowEvent: true });
但是 我建议您使用dialog API并显示包含必要信息的网页,而不要使用通知消息。
通知消息并非旨在阻止信息,在这种情况下,对话框更合适。
编辑:
// Add your notification message
var interval = window.setInterval(checkNotificationMessages, 2000);
function checkNotificationMessages() {
Office.context.mailbox.item.notificationMessages.getAllAsync(
function (asyncResult) {
if (asyncResult.status != "failed") {
if (asyncResult.value.length == 0 ) {
window.clearInterval(interval);
// Perform some action and decide whether to allow/block send
}
}
}
);
}