Xrm在Dynamics CRM 2011中未定义 [英] Xrm is undefined in Dynamics CRM 2011
问题描述
创建.js代码时,我似乎无法使Xrm变量正常工作。是否需要包含一个库或需要首先运行的功能?我需要确保正确引用ClientGlobalContext.js.aspx吗?我的思维方式是 C ++,只是想知道是否需要运行任何类型的 include命令。
I can't seem to get my Xrm variable working when I create .js code. Is there a library I need to include or a function I need to run first? Do I need to make sure that ClientGlobalContext.js.aspx is referenced correctly? I'm in a 'C++' mindset and just wondering if there is any sort of 'include' command that I need to be running.
我的js文件如下所示,如果我从第二个函数中删除了 window.parent。,则如果调用它,代码就会中断。
My js file looks like this, and if I remove the 'window.parent.' from the 2nd function the code breaks if I call it.
///<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
};
推荐答案
您的代码是否作为javascript库运行添加到了表单还是位于Web资源中?
Is your code running as a javascript library added to a form or is it sat inside a web resource?
如果是后者,则需要window.parent(如果它是HTML网络资源)。这样,您就可以访问表单上的Xrm对象。在其上方的 parent 窗口中。
If its the latter, you need window.parent if its a HTML web resource. As this gets you access to the Xrm object on the form. In the parent window above it.
如果它是附加在表单属性上的javascript库,则默认情况下XRM对象可用。
If it's a javascript library attached to the form properties then the XRM object is available by default.
当您拥有的Web资源可能不在表单的上下文中并且仍然允许您访问服务器URL和URL时,将使用ClientGlobalContext.js.aspx。例如登录用户。
The ClientGlobalContext.js.aspx is used when you have a web resource that may not be in the context of a form and still gives you access to the server url and the logged in user for example.
这篇关于Xrm在Dynamics CRM 2011中未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!