2011-12-08 59 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