如果满足某些条件,我会尝试阻止创建约会,但是行Xrm.Page.context.getEventArgs().preventDefault();
不起作用并且创建了记录。这是整个代码,调用是同步的:
var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.0/appointments?$select=activityid&$filter=<my filter>", false);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("Prefer", "odata.include-annotations=\"OData.Community.Display.V1.FormattedValue\"");
req.onreadystatechange = function () {
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 200) {
var results = JSON.parse(this.response);
if(results.value.length > 0)
{
Xrm.Utility.alertDialog('It is impossible to create the appointment.');
Xrm.Page.context.getEventArgs().preventDefault();
}
}
else {
alert(this.statusText);
}
}
};
req.send();
答案 0 :(得分:1)
您的代码应该在Xrm.Page.context.getEventArgs()
错误输出,页面的上下文对象上没有用于事件参数的属性。
您应该在save上传递执行上下文,然后使用执行上下文的事件参数来停止保存。
表单自定义:
处理程序:
function onSave(executionContext) {
if(results.value.length > 0)
{
Xrm.Utility.alertDialog('It is impossible to create the appointment.');
executionContext.getEventArgs().preventDefault();
}
}