Dynamics CRM 2013 常用JS脚本

Xrm.Page.data

获取记录的主键Id的值(getId)

var Id = Xrm.Page.data.entity.getId();

获取记录的表的逻辑名称(getEntityName)

var entityName = Xrm.Page.data.entity.getEntityName();

获取引用记录的查找值(getEntityReference)

var erEntity = Xrm.Page.data.entity.getEntityReference();
//string。表记录的逻辑名称。例如,“account”。
var entityType = erEntity.entityType;
//string。表记录的 GUID 值。
var Id = erEntity.id;
//(可选)string。表记录的名称。
var name = erEntity.name;

指示窗体中的任何列是否已被修改(getIsDirty)

// isDirty : Boolean; 如果表单中的任何列已更改,则为 true;否则为 false。
var isDirty = Xrm.Page.data.entity.getIsDirty();

立即调用窗体保存(save)

Xrm.Page.data.entity.save();

添加在触发 OnSave事件时要调用的函数(addOnSave)

//functionName:绑定的方法名
Xrm.Page.data.entity.addOnSave(functionName);

Xrm.Page.ui

获取记录的窗体类型(getFormType)

//0:未定义的;1:新建;2:更新;3:只读;4:禁用;6:批量编辑
var type = Xrm.Page.ui.getFormType();

显示表单级别通知(setFormNotification)

//message:string,必填,消息的文本
//level:string,必填,消息的级别:ERROR,WARNING,INFO
//uniqueId:string,必填,消息的唯一标识符,稍后可与 clearFormNotification 一起使用以删除通知。
Xrm.Page.ui.setFormNotification(message, level, uniqueId);

删除表单级别通知(clearFormNotification)

//uniqueId:使用 setFormNotification 方法设置的要清除的消息的唯一标识符。
Xrm.Page.ui.clearFormNotification(uniqueId);

关闭窗体(close)

Xrm.Page.ui.close();

Xrm.Page.getAttribute

获取字段的值(getValue)

//attributeName:字段逻辑名
var attributeValue = Xrm.Page.getAttribute("attributeName").getValue();

设置字段的值(setValue)

//attributeName:字段逻辑名
//attributeValue:设置字段的值
Xrm.Page.getAttribute("attributeName").setValue(attributeValue);

//设置查找类型的值
var lookupObject = {};
lookupObject.id = attribute.guid;
lookupObject.entityType = attribute.logicalName;
lookupObject.name = attribute.name;
var attributeValue = [];
attributeValue[0] = lookupObject;
Xrm.Page.getAttribute("attributeName").setValue(attributeValue);

获取字段的必填性(setRequiredLevel)

//attributeName:字段逻辑名
//选填:none;必填:required;业务推荐填写:recommended;
var attributeRequiredLevel = Xrm.Page.getAttribute("attributeName").getRequiredLevel();

设置字段的必填性(setRequiredLevel)

//attributeName:字段逻辑名
//requirementLevel:必填性;选填:none;必填:required;业务推荐填写:recommended;
Xrm.Page.getAttribute("attributeName").setRequiredLevel(requirementLevel);

获取字段的提交模式(setSubmitMode)

//attributeName:字段逻辑名
//always:数据始终与保存一起发送;
//never:数据从不与保存一起发送。使用此值时,无法编辑此列的窗体中的列;
//dirty:默认行为。当数据发生更改时,数据将与保存一起发送;
var attributeSubmitMode = Xrm.Page.getAttribute("attributeName").getSubmitMode();

设置字段的提交模式(setSubmitMode)

//attributeName:字段逻辑名
//mode:提交模式,string;
//always:数据始终与保存一起发送;
//never:数据从不与保存一起发送。使用此值时,无法编辑此列的窗体中的列;
//dirty:默认行为。当数据发生更改时,数据将与保存一起发送;
Xrm.Page.getAttribute("attributeName").setSubmitMode("mode");

设置字段OnChange事件(addOnChange)

//attributeName:字段逻辑名
//functionName:绑定的方法名
Xrm.Page.getAttribute("attributeName").addOnChange(functionName);

移除字段OnChange事件(removeOnChange )

//attributeName:字段逻辑名
//functionName:移除的方法名
Xrm.Page.getAttribute("attributeName").removeOnChange(functionName);

获取字段的逻辑名称(getName)

//attributeName:字段逻辑名
var attributeLogicalName = Xrm.Page.getAttribute("attributeName").getName();

获取字段的选项集对象数组(getOptions)

//attributeName:字段逻辑名
var options = Xrm.Page.getAttribute("attributeName").getOptions();

获取当前选定选项的文本(getText)

//attributeName:字段逻辑名
var optionText = Xrm.Page.getAttribute("attributeName").getText();

获取字段是否已修改未保存(getIsDirty)

//attributeName:字段逻辑名
var isDirty = Xrm.Page.getAttribute("attributeName").getIsDirty();

Xrm.Page.getControl

获取字段的标签(getLabel)

//attributeName:字段逻辑名
var attributeLabel = Xrm.Page.getControl("attributeName").getLabel();

设置字段是否可见(setVisible)

//attributeName:字段逻辑名
//bool: 可见:true;不可见:false;
Xrm.Page.getControl("attributeName").setVisible(bool);

设置字段是否禁用(setDisabled)

//attributeName:字段逻辑名
//bool: 禁用:true;可用:false;
Xrm.Page.getControl("attributeName").setDisabled(bool);

获取字段是否禁用(getDisabled)

//attributeName:字段逻辑名
var attributeValue = Xrm.Page.getControl("attributeName").getDisabled();

新增选项集选项(addOption)

//attributeName:字段逻辑名
//option:添加的选项
//index:放置新选项的索引位置。如果未提供,则该选项将添加到末尾。
var option = {};
option.text = "Test";
option.value = 1;
Xrm.Page.getControl("attributeName").addOption(option,index);

清空选项集选项(clearOptions)

//attributeName:字段逻辑名
Xrm.Page.getControl("attributeName").clearOptions();

移除选项集选项(removeOption)

//attributeName:字段逻辑名
//optionValue:选项集选项值
Xrm.Page.getControl("attributeName").removeOption(optionValue);

设置显示字段的错误消息(setNotification)

//attributeName:字段逻辑名
//message:要显示的消息
//uniqueId:使用 clearNotification 方法时用于清除此消息的 ID
Xrm.Page.getControl("attributeName").setNotification(message,uniqueId);

清除字段显示的错误消息(clearNotification)

//attributeName:字段逻辑名
//uniqueId:使用 clearNotification 方法时用于清除此消息的 ID
Xrm.Page.getControl("attributeName").clearNotification(uniqueId);

添加预搜索(addPreSearch)

//attributeName:字段逻辑名
//functionName:绑定的方法名
Xrm.Page.getControl("attributeName").addPreSearch(functionName);

添加自定义筛选器(addCustomFilter)

//attributeName:字段逻辑名
//fetchXml:要应用的 fetchXml 筛选器元素
var fetch = "<filter type=\"and\">"+
            "<condition attribute=\"address1_city\" operator=\"eq\" value=\"Redmond\" />"+
            "</filter>"
Xrm.Page.getControl("attributeName").addCustomFilter(fetchXml);

添加自定义视图(addCustomView)

//attributeName:字段逻辑名
//viewId:字符串,视图的 GUID 的字符串表示形式
//entityName:字符串,实体逻辑名称
//viewDisplayName:字符串,视图的名称
//viewDisplayName:字符串,视图的名称
//fetchXml:字符串,视图的 fetchXml 查询。
//layoutXml:字符串,定义视图布局的 XML。
//isDefault:布尔值,指示视图是否应为默认视图。
// 指定视图的GUID(任意)
var viewId = "00000000-0000-0000-0000-00000000000001";
// 查找实体的逻辑名称
var entityName = "account";
// 指定视图的名称
var viewDisplayName = "可用的客户视图";
// 视图的fetchXml查询
var fetchXml = ["<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
                  "<entity name='account'>" +
                    "<attribute name='name' />" +
                    "<attribute name='accountid' />" +
                    "<attribute name='createdon' />" +
                    "<order attribute='name' descending='false' />" +
                    "<filter type='and'>" +
                      "<condition attribute='statecode' operator='eq' value='0' />" +
                    "</filter>" +
                  "</entity>" +
                "</fetch>"];
// 指定视图布局XML
var layoutXml = ["<grid name='resultset' object='1' jump='name' select='1' icon='0' preview='1'>",
                 "<row name='result' id='accountid'>",
                 "<cell name='name' width='100'/>",
                 "<cell name='createdon' width='100'/>",
                 "</row>",
                 "</grid>"];
// 是否设置为默认视图
var isDefault = true;
Xrm.Page.getControl("attributeName").addCustomView(viewId, entityName, viewDisplayName, fetchXml, layoutXml, isDefault);
posted @   Destiny、Yang  阅读(75)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 实操Deepseek接入个人知识库
· CSnakes vs Python.NET:高效嵌入与灵活互通的跨语言方案对比
· 【.NET】调用本地 Deepseek 模型
· Plotly.NET 一个为 .NET 打造的强大开源交互式图表库
· 上周热点回顾(2.17-2.23)
点击右上角即可分享
微信分享提示