2011-12-08 66 views
3

我創建.js代碼時似乎無法讓我的Xrm變量工作。我需要包含一個庫還是需要首先運行的函數?我是否需要確保ClientGlobalContext.js.aspx被正確引用?我處於'C++'的心態,只是想知道是否有任何需要運行的'include'命令。Xrm在Dynamics CRM 2011中未定義

我的js文件看起來像這樣,如果我刪除'window.parent。'從第二個函數中,如果我打電話,代碼就會中斷。

///<reference path="C:\Users\steve.lee\Downloads\XrmPage-vsdoc.js"/> 

if (typeof (SDK) == "undefined") 
{ SDK = { __namespace: true }; } 

SDK.XRM = { 
    getCurrentControl: function() { 
     var currentControl = Xrm.Page.ui.getCurrentControl(); 
     if (currentControl == null) { 
      alert("No controls currently have focus."); 
     } 
     else { 
      alert("The control for the '" + currentControl.getLabel() + "' attribute currently has focus."); 
     } 
    }, 

    getCurrentGUID: function() { 

     if (window.parent.Xrm.Page.data.entity != null) { 
      var GUIDvalue = window.parent.Xrm.Page.data.entity.getId(); 
      if (GUIDvalue != null) { 
       return GUIDvalue; 
      } 
      else { 
       return null; 
      } 
     } 
     else { 
      return null; 
     } 
    }, 
__namespace: true 
}; 
+0

請添加代碼示例或描述特定的錯誤。 – ccellar

+0

錯誤是一個通用的JavaScript彈出,其中說'Xrm.Page.data.entity'爲空或不是對象 – Steve

回答

9

正在運行的JavaScript庫添加到您的代碼形式,還是坐在一個網絡資源?

如果它是後者,則需要window.parent(如果其爲HTML Web資源)。這樣可以訪問表單上的Xrm對象。在父母之上的窗口中。

如果它是附加到表單屬性的JavaScript庫,那麼默認情況下XRM對象可用。

ClientGlobalContext.js.aspx用於您擁有可能不在表單上下文中的Web資源,並且仍然允許您訪問服務器URL和登錄用戶的情況。

+0

啊,這就解釋了一切。是的,現在我的js庫位於我的htm web資源中。我不想通過額外的步驟將庫連接到表單上的事件處理程序。謝謝! – Steve

1

的XRM變量應可無任何包含或CRM建立正常的JS代碼2011

的基本覆蓋here