VicTang

  首先该方法不能写在页面的onload中,因为当从子网格返回常规表单的时候ribbon区域会重新加载而常规表单所在的iframe区域是不会被刷新的,所以如果写在onload中的话就控制的不那么完全了,我采取的方式是利用按钮的Enables Rules中CustomRule(A rule that calls a function within a JScript library)这样每次加载都能调用到了。

      下面说说代码,先通过F12获取要控制的自定义按钮的ID,例如“new_areacost|NoRelationship|Form|AreaGroupAreaGroup.Mscrm.Form.new_areacost.MainTab.area.submit-Large”着实有点长啊,剩下的就很简单了

var WinbuttonID="new_areacost|NoRelationship|Form|AreaGroupAreaGroup.Mscrm.Form.new_areacost.MainTab.area.submit-Large";
var WinBtn = window.top.document.getElementById(WinbuttonID);
WinBtn.style.display=\'\';
WinBtn.style.display=\'none\';

该方法得到了曾丹同学的提示表示下感谢,在他的提示下果断舍弃了经过两天的努力都达不到效果的第二种方法。  

      第二种则显得有些繁琐而且时而好用时而又不好用,为什么说它时而好用时而又不好用呢,因为之前的一个系统使用成功过但在这个系统中却又不行了。之所以说它不好用是因为parentwindow.document.getElementById(ribbonid)抓取出来的ribbon始终都是空,不知道为什么。

var button=Xrm.Page.ui.controls.get("new_name")._control._element.ownerDocument;
var parentwindow=GetFormWindows(button);
var display=true;
if(parentwindow!=null) 
{ 
    var ribbon=parentwindow.document.getElementById(ribbonid); 
    if(ribbon!=null&&display) 
    {
		ribbon.style.display=\'none\';
    }
     else if(ribbon!=null)
    {           
		 ribbon.style.dispaly=\'\';     
    }
 }

function GetFormWindows(cus_document)
{
     return cus_document.defaultView || cus_document.parentWindow; 
}

  

分类:

技术点:

相关文章: