【问题标题】:Disable view picker DIV is not accessible in MS CRM禁用视图选择器 DIV 在 MS CRM 中不可访问
【发布时间】:2016-04-24 19:00:41
【问题描述】:

我正在尝试禁用 2016 年帐户查找的视图选择器。

代码工作正常,我的意思是我没有收到任何错误,但代码无法找到“parentaccountid”的特定 DIV。

我可以在 Elements 中看到它:

但当代码尝试获取 DIV 的元素时,它会返回 {null} - document.getElementByid("parentaccountid");

我的代码在加载机会页面时运行。

即使在这一步,我也可以看到特定的 DIV 元素 - id:parentaccountid

我仍然得到 {null} 值:

在 2013 年,我已经看到它运行良好。 抱歉,我没有数据可以在这里分享,但它工作正常。

下面是代码:

function DisablePick()
{
	VULoader();
	
	//call this function from OnLoad handler
	function VULoader(){
		var myLookup1;
              alert("Hello..I am Here");
	      var fetch = "<fetch mapping='logical'>"
             +"<entity name='account'>"             
             +"<attribute name='name'/>"                   
             +"<filter type='and'>" 
            +"<condition attribute='name' operator='eq' value='Blue Yonder Airlines (sample)' />" 
            +"</filter>" 
      +"</link-entity>" 
   +"</entity>" 
+"</fetch>";
		
		myLookup1 = new XrmLookupField("parentaccountid");
		myLookup1.AddLockedView(
			//sViewId
			myLookup1.NewGuid() ,
			//sEntityName
			"account",
			//sViewDisplayName
			"My Locked Custom View",
			//sFilterXml
			fetch,
			//sFilterLayout
			layout(1, "name", "accountid")
				.column("name", 200)
			.toString()
		);
	}

	function XrmLookupField(sId) {
		var xlf = this;
		//control instance
		xlf.Ctl = Xrm.Page.getControl(sId);
		//dom instance
		xlf.Dom = document.getElementById(sId);
		//jquery instance
		xlf.$ = $(xlf.Dom);
	  
		/* 2013 addition --- Inline Control instance --- */
		xlf.$i = $("#" + sId + "_i");
	 
		//use that to disable the view picker
		xlf.DisableViewPicker = function () { 
			/* 2013 addition --- The attribute capitalization changed */
			xlf.SetParameter("disableviewpicker", "1"); 
		}
		//use that to enable the view picker
		xlf.EnableViewPicker = function () { 
			/* 2013 addition --- The attribute capitalization changed */
			xlf.SetParameter("disableviewpicker", "0");  
		}
		 
		//set undocumented attributes
			xlf.SetParameter = function (sName, vValue) { 
			xlf.$.attr(sName, vValue);  
	 
			/* 2013 addition --- Also change the inline contorl value */
			xlf.$i.attr(sName, vValue);
		}   
		 
		//add locked view
		xlf.AddLockedView = function (sViewId, sEntityName, sViewDisplayName, sFilterXml, sFilterLayout) {
			//first enable the view picker
			xlf.EnableViewPicker();
			//add the custom view (last parameter set the view as default)
			xlf.Ctl.addCustomView(sViewId, sEntityName, sViewDisplayName, sFilterXml, sFilterLayout, true);
			//lock the view picker
			xlf.DisableViewPicker();
		}
		//create new guid
		xlf.NewGuid = function () {
			var d = new Date().getTime();
			var guid = '{xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx}'.replace(/[xy]/g, function (c) {
				var r = (d + Math.random() * 16) % 16 | 0;
				d = Math.floor(d / 16);
				return (c == 'x' ? r : (r & 0x7 | 0x8)).toString(16);
			});
			return guid;
		}
	}
}

提几点:

我在加载机会页面时调用 DisablePicker 方法。 是的,我已经检查过是否有任何重复的 id,但我没有找到。

我也尝试在加载帐户字段时运行此方法,但没有响应。

如果我在页面加载并打开查找后手动从浏览器中将 DIV 本身的属性 disableviewpicker 值从 0 更改为 1,那么它将使更改的值生效。

我真的不知道它为什么会这样,我只需要知道我到底哪里出错了,或者这是一个产品错误,但我不认为它是。作为一个非常基本的行为。

PS:对于我的非 MS CRM 朋友,我无法更改 DIV 或除我的 JavaScript 代码之外的任何内容。

【问题讨论】:

    标签: javascript html dynamics-crm dynamics-crm-2013 dynamics-crm-2015


    【解决方案1】:

    您的表单代码在与实际 CRM 表单不同的框架中执行;它在 ClientApiWrapper.aspx 页面中运行。因此,要从表单脚本访问要修改的表单元素,您的表单代码应该使用parent.document.getElementById 而不是document.getElementById

    当您使用浏览器的开发工具时,控制台执行的默认框架也不是包含表单元素的框架,也不是包含表单代码的框架。针对正确帧执行的最简单方法是使用开发工具中的函数来切换帧。在 Firefox 中,该按钮如下所示:

    将您的框架设置为 ClientApiWrapper.aspx 是最简单的,因为它提供对加载到您的表单上的库以及 CRM 客户端 API 的访问。

    【讨论】:

    • 是的,我可以使用 parent.document 获取 DIV,但我现在有两个问题:看看你是否也能提供帮助? 1) 发生这种情况是因为 CRM 2013 页面的加载方式与 CRM 2016 不同? 2)如果是,我是否需要在加载时将我的框架设置为 ClientApiWrapper.aspx,如果是,那么如何或只需要使用 Xrm.Page.context.client.getClient 代码或有其他方法可以做。我发现了一些博客,但我没有得到。是的,非常感谢您的意见。
    • 1) 是的,在某些时候页面结构发生了变化,我不记得具体是什么时候了。 2)您发布到CRM 中的代码不必担心切换帧,它总是可以做到parent.document.getElementById。您只需要在使用开发工具时关注帧切换。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-28
    • 2015-11-27
    • 1970-01-01
    相关资源
    最近更新 更多