我想在賬戶查詢禁用於2016年禁用視圖選擇器DIV是無法訪問在MS CRM
視圖選擇器的代碼工作正常,我的意思是,我沒有得到任何錯誤,但這些代碼並沒有能夠找到「parentaccountid」的特定DIV。
但它返回{NULL}當代碼試圖獲得DIV的元素 - 的document.getElementById(「parentaccountid」);
我的代碼的機會頁的負荷運行。
即使在這個步驟中,可以看到特定的DIV元素 - ID:parentaccountid
在哪裏,因爲我仍然得到{}空值:
如在哪裏在2013年我看到它工作得很好。 對不起,我沒有數據在這裏分享,但它工作正常。
這裏是下面的代碼:
function DisablePick()
{
\t VULoader();
\t
\t //call this function from OnLoad handler
\t function VULoader(){
\t \t var myLookup1;
alert("Hello..I am Here");
\t 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>";
\t \t
\t \t myLookup1 = new XrmLookupField("parentaccountid");
\t \t myLookup1.AddLockedView(
\t \t \t //sViewId
\t \t \t myLookup1.NewGuid() ,
\t \t \t //sEntityName
\t \t \t "account",
\t \t \t //sViewDisplayName
\t \t \t "My Locked Custom View",
\t \t \t //sFilterXml
\t \t \t fetch,
\t \t \t //sFilterLayout
\t \t \t layout(1, "name", "accountid")
\t \t \t \t .column("name", 200)
\t \t \t .toString()
\t \t);
\t }
\t function XrmLookupField(sId) {
\t \t var xlf = this;
\t \t //control instance
\t \t xlf.Ctl = Xrm.Page.getControl(sId);
\t \t //dom instance
\t \t xlf.Dom = document.getElementById(sId);
\t \t //jquery instance
\t \t xlf.$ = $(xlf.Dom);
\t
\t \t /* 2013 addition --- Inline Control instance --- */
\t \t xlf.$i = $("#" + sId + "_i");
\t
\t \t //use that to disable the view picker
\t \t xlf.DisableViewPicker = function() {
\t \t \t /* 2013 addition --- The attribute capitalization changed */
\t \t \t xlf.SetParameter("disableviewpicker", "1");
\t \t }
\t \t //use that to enable the view picker
\t \t xlf.EnableViewPicker = function() {
\t \t \t /* 2013 addition --- The attribute capitalization changed */
\t \t \t xlf.SetParameter("disableviewpicker", "0");
\t \t }
\t \t
\t \t //set undocumented attributes
\t \t \t xlf.SetParameter = function (sName, vValue) {
\t \t \t xlf.$.attr(sName, vValue);
\t
\t \t \t /* 2013 addition --- Also change the inline contorl value */
\t \t \t xlf.$i.attr(sName, vValue);
\t \t }
\t \t
\t \t //add locked view
\t \t xlf.AddLockedView = function (sViewId, sEntityName, sViewDisplayName, sFilterXml, sFilterLayout) {
\t \t \t //first enable the view picker
\t \t \t xlf.EnableViewPicker();
\t \t \t //add the custom view (last parameter set the view as default)
\t \t \t xlf.Ctl.addCustomView(sViewId, sEntityName, sViewDisplayName, sFilterXml, sFilterLayout, true);
\t \t \t //lock the view picker
\t \t \t xlf.DisableViewPicker();
\t \t }
\t \t //create new guid
\t \t xlf.NewGuid = function() {
\t \t \t var d = new Date().getTime();
\t \t \t var guid = '{xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx}'.replace(/[xy]/g, function (c) {
\t \t \t \t var r = (d + Math.random() * 16) % 16 | 0;
\t \t \t \t d = Math.floor(d/16);
\t \t \t \t return (c == 'x' ? r : (r & 0x7 | 0x8)).toString(16);
\t \t \t });
\t \t \t return guid;
\t \t }
\t }
}
幾點提:
我呼籲有機會頁面加載DisablePicker方法。 是的,我已經檢查是否有重複的ID是否存在,但我沒有找到任何。
我試圖運行此帳戶字段負載的方法,但沒有響應。
如果我在DIV本身中將屬性disableviewpicker值從0更改爲1,則在頁面加載後手動從瀏覽器中打開&打開查找,然後它將採用更改的值的效果。
真的,我不明白爲什麼它的行爲如此,我只需要知道我究竟在哪裏出錯或者它是產品錯誤,但我不認爲它是。作爲一個非常基本的行爲。
PS:對於我的非MS CRM朋友,我無法更改DIV或除JavaScript代碼之外的任何內容。
是的,我可以通過使用parent.document來獲得DIV,但我現在有兩個問題:看看你是否也可以提供幫助? 1)這是因爲CRM 2013頁面加載的方式與CRM 2016不同嗎? 2)如果是的話,我是否需要在加載時將我的框架設置爲ClientApiWrapper.aspx,然後如何或僅僅需要使用Xrm.Page.context.client.getClient代碼還是有其他方法。我發現了幾個博客,但我沒有得到。是的,非常感謝您的意見。 – Deep
1)是的,在某個時候頁面結構發生了變化,我不記得具體時間。 2)您發佈到CRM中的代碼不必擔心切換幀,它總是可以執行'parent.document.getElementById'。當您使用開發工具時,您只需關心幀切換。 – Polshgiant