var FORM_TYPE_CREATE = 1;
var FORM_TYPE_EDIT = 2;
var formType = "";
function PageOnLoad() {
var new_shopid = Xrm.Page.getAttribute("new_shopid");
var new_shopidControl = Xrm.Page.getControl("new_shopid");
//如果为新建,则网点为必填项
formType = Xrm.Page.ui.getFormType();
if (formType == FORM_TYPE_CREATE) {
new_shopid.setRequiredLevel("required"); //这里一行代码可以替换下面的PageOnSave(ExecutionObj)这个方法
}
else if (formType == FORM_TYPE_EDIT) {
if (new_shopidControl != undefined) {
new_shopidControl.setDisabled(true);
}
}
}
function PageOnSave(ExecutionObj) {
var new_shopid = Xrm.Page.getAttribute("new_shopid");
var new_shopidControl = Xrm.Page.getControl("new_shopid");
if (new_shopid == null) {
alert("网点为必填项");
new_shopidControl.setFocus();//不能加这个,不然后面的ExecutionObj.getEventArgs().preventDefault();不起作用。
ExecutionObj.getEventArgs().preventDefault();//不能保存
}
}