Microsoft Dynamics CRM2011 Javascript

一、CRM2011 Javascript  禁用子网格

// Disable a subgrid on a form 
function disableSubgrid(subgridName) {
    document.getElementById(subgridName + "_span").disabled = "true";
}

来自http://www.magnetismsolutions.co.nz/blog/paul/12-02-28/Disable_Subgrids_with_Javascript_in_Dynamics_CRM_2011.aspx

二、//一个表单上面子网格,最多是可以显示5个子网格的数据

//从第六个开始就不再自动加载数据了,需要点击里面连接的.下面代码就是为了解决这个问题的。
1.

function getLinksWithClassName(classname) {
var bdy = document.getElementsByTagName("body")[0];
var els = [];
var re = new RegExp('\b' + classname + '\b');
var lnks = bdy.getElementsByTagName("a");

for (var i = 0, j = lnks.length; i < j; i++)
if (re.test(lnks[i].className))
els.push(lnks[i]);

return els;
}

2.

var subgrids = Xrm.Page.ui.controls.get(function (control, index) {
return control.getControlType() == "subgrid";
});

if (subgrids.length > 4) {
for (var i = 4; i < subgrids.length; i++)
subgrids[i].refresh();
}

来自:http://blog.customereffective.com/blog/2011/12/crm-2011excessive-sub-gridding.html

三、设置选项卡为不可见

 Xrm.Page.ui.tabs.get(0).setVisible(false);

//将表单上的左边的选项卡设为不可见
function setTabsInvisible() {
var tab = Xrm.Page.ui.tabs;
if (tab != null && tab.getLength() > 0) {
for (var i = 0; i < tab.getLength() ; i++) {
if (tab.get(i) != null && tab.get(i).getVisible() == true) {
tab.get(i).setVisible(false);
}
}
}
}

四、Json格式转为日期格式

function converJsonToDate(value) {
    var a;
    if (typeof value === 'string') {
        a = /Date(([-+]?d+))/.exec(value);
        if (a) {
            return new Date(parseInt(value.replace("/Date(", "").replace(")/", ""), 10));
        }
    }
    return value;
};

 五、

前台获取字段属性:contentIFrame.window.Xrm.Page.getAttribute("new_statuscode").controls.get(0).setDisabled(false)                                                       
前台获取字段值:contentIFrame.window.Xrm.Page.getAttribute("new_subject").getValue()                                                                 
前台获取lookup字段值: contentIFrame.window.Xrm.Page.getAttribute("new_costfrom").getValue()[0].id                                                                
获取当前登录用户:Xrm.Page.context.getUserId()                                                                
获得当前页面类型:Xrm.Page.ui.getFormType()                                                                 
获得当前实体名称:contentIFrame.Xrm.Page.data.entity.getEntityName()                                                                
刷新Ribbon工具条:Xrm.Page.ui.refreshRibbon();                                                                
给lookup字段赋值:var tmp=[{ id: PaymentInfo.new_distributor.Id, name: PaymentInfo.new_distributor.Name, typename: PaymentInfo.new_distributor.LogicalName}];Xrm.Page.getControl("new_budget").getAttribute().setValue(tmp);                                                        
原文地址:https://www.cnblogs.com/allenhua/p/3197745.html