当我创建 .js 代码时,我似乎无法让 Xrm 变量工作。是否有我需要包含的库或我需要先运行的函数?我是否需要确保正确引用 ClientGlobalContext.js.aspx?我处于“C++”心态,只是想知道是否有任何类型的“include”命令需要运行。
我的 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
};
您的代码是作为添加到表单中的 javascript 库运行还是位于 Web 资源中?
如果是后者,如果它是 HTML Web 资源,则需要 window.parent。这样您就可以访问表单上的 Xrm 对象。在里面parent其上方的窗口。
如果它是附加到表单属性的 javascript 库,则默认情况下 XRM 对象可用。
当您拥有的 Web 资源可能不在表单上下文中但仍然允许您访问服务器 URL 和登录用户时,请使用 ClientGlobalContext.js.aspx。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)