【发布时间】:2016-04-24 19:00:41
【问题描述】:
我正在尝试禁用 2016 年帐户查找的视图选择器。
代码工作正常,我的意思是我没有收到任何错误,但代码无法找到“parentaccountid”的特定 DIV。
但当代码尝试获取 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