Dynamics CRM JS


前言

用到的我才记录

表单上Tab的显隐

function setTabVisableByName(tabName, flag) {
    var control = Xrm.Page.ui.tabs.get(tabName);
    control.setVisible(true/false);
}

禁用整个表单

Xrm.Page.ui.controls.forEach(function (control, index) {
        var controlType = control.getControlType();
        if (controlType != "iframe" && controlType != "webresource" && controlType != "subgrid")) {
            control.setDisabled(true/false);
        }
    });

获取字段

//获取创建时间
var CreateTime = Xrm.Page.getAttribute("createdon").getValue();//Tips:获取到的时间是object类型
var GetMonth = CreateTime.getMonth(); //Tips:获取到的是下标

//去掉optionset
Xrm.Page.getControl("字段").removeOption("100000000");

判断窗体的状态

if (Xrm.Page.ui.getFormType() == 1){
    //1:Create
}
else{
    //0:Undefined
    //2:Update
    //3:Read Only
    //4:Disabled
    //6:Bulk Edit
}