该代码需要配置OnSave事件。并启用“将执行上下文作为第一个参数” 。
OnSave事件在表单加载和保存时都会触发,所以对于Alert的动作,需要写好判断条件,防止加载时触发。
本代码是通过判断是否字段未保存来防止触发的。
function SaveAlert(ExecutionObj) {
var project_stage = Xrm.Page.getAttribute("new_productproject_stage").getValue();
if (project_stage >= 7) {
if (Xrm.Page.getAttribute("new_internalresourcesid").getIsDirty() || Xrm.Page.getAttribute("new_internalresourcesaleid").getIsDirty()) {
if (confirm("生产公司简称,销售公司简称变更将会邮件通知总经理,请点击确认,或者取消变更。")) {
}
else {
ExecutionObj.getEventArgs().preventDefault();//阻止保存操作
}
}
}
}