[英]Cannot access Xrm.Page.context from within HTML web resource in CRM
I'm trying access the Xrm.Page.data object from within an HTML web resource. 我正在尝试从HTML Web资源中访问Xrm.Page.data对象。 I try to access the Xrm context, I find that it is undefined or that Xrm.Page is null. 我尝试访问Xrm上下文,发现它未定义或Xrm.Page为空。 The code for the web resource is as follows: Web资源的代码如下:
function GetClientUrl() {
if (typeof window.parent.Xrm.Page.context == "object") {
clientUrl = window.parent.Xrm.Page.context.getClientUrl();
}
var ServicePath = "/XRMServices/2011/Organization.svc/web";
return clientUrl + ServicePath;
}
It's just appen when it's embedded in an HTML web resource. 当它嵌入HTML Web资源中时,它才适用。 Can anyone explain what I'm doing wrong? 谁能解释我在做什么错? Thank you. 谢谢。
Microsoft provided a function to get the context for web resources. Microsoft提供了获取Web资源上下文的功能。
You need to add a reference to: 您需要添加对以下内容的引用:
<script src="../ClientGlobalContext.js.aspx" type="text/javascript" ></script>
Then you can get the context like so: 然后,您可以像这样获得上下文:
var context = GetGlobalContext();
clientUrl = context.getClientUrl();
Documentation: GetGlobalContext function and ClientGlobalContext.js.aspx (client-side reference) 文档: GetGlobalContext函数和ClientGlobalContext.js.aspx(客户端参考)
Reference ClientGlobalContext on your web resource and you should then be able to access Xrm object like you do on any CRM form. 在Web资源上引用ClientGlobalContext ,然后您应该能够像在任何CRM表单上一样访问Xrm对象。 You don't have to access the parent page's Xrm object. 您不必访问父页面的Xrm对象。
<head>
<title>HTML Web Resource</title>
<script src="ClientGlobalContext.js.aspx" type="text/javascript" ></script>
</head>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.