我在Dynamics CRM中使用Xrm.Navigation.openConfirmDialog进行确认。我想知道它是否能在成功或失败时返回一个值。
下面是我的源码:
function confirmationBox(promptText, w, h) {
var confirmationStrings = {
text: promptText, title: "ConfirmationBox",
cancelButtonLabel: "No", confirmButtonLabel: "Yes"
};
var confirmationDimension = { height: h, width: w };
Xrm.Navigation.openConfirmDialog(confirmationStrings, confirmationDimension).then(
function (success) {
if (success.confirmed) {
console.log("Confirmed");
return true;
}
else {
console.log("Not Confirmed");
return false;
}
});
}在下面的代码中,我调用了这个函数,但是这个方法返回null所有的情况。任何人都可以帮助理解为什么它不返回任何内容。
var temp = confirmationBox(promptText, 350, 450);
console.log(temp);发布于 2019-10-09 20:51:09
成功和错误函数只是回调函数。openConfirmDialog不返回回调函数的结果。
您可以更改您的函数,以便传递您的成功回调。
function confirmationBox(promptText, w, h, callback) {
var confirmationStrings = {
text: promptText, title: "ConfirmationBox",
cancelButtonLabel: "No", confirmButtonLabel: "Yes"
};
var confirmationDimension = { height: h, width: w };
Xrm.Navigation.openConfirmDialog(confirmationStrings, confirmationDimension).then(
function (success) {
if (success.confirmed) {
callback();
}
else {
console.log("Not Confirmed");
return false;
}
});
}免责声明,此代码可能需要调整才能工作。
发布于 2019-10-14 20:05:07
openConfirmDialog退货承诺
所以你可以使用像这样的东西
var confirmationBox = function(promptText, w, h) {
return new Promise(function (resolve, reject) {
var confirmationStrings = {
text: promptText, title: "ConfirmationBox",
cancelButtonLabel: "No", confirmButtonLabel: "Yes"
};
var confirmationDimension = { height: h, width: w };
Xrm.Navigation.openConfirmDialog(confirmationStrings, confirmationDimension).then(
function (success) {
if (success.confirmed) {
console.log("Confirmed");
resolve(true);
}
else {
console.log("Not Confirmed");
resolve(false);
}
}, function (error) {
reject(error);
});
}
}
confirmationBox(promptText, 350, 450).then(function(result){
console.log(result);
}).catch(function(error){
//handle error
console.log(error);
});https://stackoverflow.com/questions/58303161
复制相似问题