Microsoft Dynamics CRM4.0 的表单Form的左侧导航栏默认只能有详细信息details, 销售sales,市场marketing,服务service这几个分组,如果一个实体的相关实体太多就可能需要增加分组,但系统目前无法提供标准的增加分组的功能,所以整理了一个JS函数以供大家参考
把以下代码拷贝到Form的Onload中即可(以下以account为例)
var demoNavBar1 = new JsNavBar("Demo1:"); --Demo1 为分组的显示名称
demoNavBar1.AddNavBarItem("navSubAct");--navSubAct 为原链接的id(一般为CRM中一对多关系的名称)
demoNavBar1.Show(1);--分组显示的顺序(从1开始)
代码
JsNavBar = function(displayName) {
var navBarDisplayName = displayName;
var navBarItemArray = new Array();
JsNavBar.prototype.AddNavBarItem = function(navBarItemId) {
navBarItemArray[navBarItemArray.length] = document.getElementById(navBarItemId);
};
JsNavBar.prototype.Show = function(orderNumber) {
var crmNavBar = document.getElementById("crmNavBar");
if (crmNavBar != null) {
var navBarItems = document.createElement("UL");
navBarItems.style.display = "inline";
navBarItems.className = "ms-crm-Nav-Group-Subareas";
for (i = 0; i < navBarItemArray.length; i++) {
if (navBarItemArray[i] != null) {
navBarItems.appendChild(navBarItemArray[i]).parentNode;
}
}
if (navBarItems.hasChildNodes()) {
var alink="<A id=" + navBarDisplayName + " class=ms-crm-Nav-Group-Heading title='Click here for more areas' tabIndex=0 onclick='return false;' href='javascript:onclick();' target=_self><NOBR class=ms-crm-Nav-Group-Title>" + navBarDisplayName + "</NOBR> <IMG class=ms-crm-Nav-Group-RightIcon alt='Expanded, click to collapse' src='/_imgs/navup.gif'></A>";
var newNavBar = document.createElement("LI");
newNavBar.className = "ms-crm-Nav-Group";
newNavBar.innerHTML = alink;
newNavBar.appendChild(navBarItems);
if (crmNavBar.childNodes.length >= orderNumber) {
var secondNav = crmNavBar.childNodes[orderNumber-1];
crmNavBar.insertBefore(newNavBar, secondNav);
}
else {
crmNavBar.appendChild(newNavBar);
}
}
}
}
}
var demoNavBar1 = new JsNavBar("Test1:");
demoNavBar1.AddNavBarItem("navSubAct");
demoNavBar1.Show(1);
var demoNavBar2 = new JsNavBar("Test2:");
demoNavBar2.AddNavBarItem("navRelationships");
demoNavBar2.Show(2);