dynamics crm 一些常用的js

整理下平时CRM开发中用到的一些基本的js操作

取值:

var oResult = Xrm.Page.getAttribute(sFieldNames).getValue();

var oResult = Xrm.Page.getControl(sFieldNames).getAttribute().getValue();

赋值:

Xrm.Page.getAttribute(sFieldName).setValue(object);

OptionSet: Xrm.Page.getAttribute(sFieldName).setValue(1);  //OptionSet的对应选项的Value

Lookup: Xrm.Page.getAttribute(sFieldName).setValue([{ id:"record id", name: "sValue", entityType: "Entity Name" }]);

 

提示指定错误:

Xrm.Page.getControl(sFieldName).setNotification(sErrorMessage);

清除错误提示:

Xrm.Page.getControl(sFieldName).clearNotification();

 

设置Read Only:

Xrm.Page.getControl(sFieldName).setDisabled(true);

设置Enable:

Xrm.Page.getControl(sFieldName).setDisabled(false);

 

设置必填:

Xrm.Page.getAttribute(sFieldName).setRequiredLevel("required");

设置可选:

Xrm.Page.getAttribute(sFieldName).setRequiredLevel("none");

 

添加事件:

Xrm.Page.getControl(sFieldName).getAttribute().addOnChange(fnOnChange);

 

相关文章