简体   繁体   English

无法从CRM中的HTML Web资源中访问Xrm.Page.context

[英]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.

相关问题 无法从CRM 2011中的HTML Web资源中访问Xrm.Page.data - Cannot access Xrm.Page.data from within HTML web resource in CRM 2011 Dynamics CRM 365 - 无法访问HTML Web资源中的Xrm.Page.entity - Dynamics CRM 365 - Cannot access Xrm.Page.entity in HTML web ressource 无法从打开的框架网络资源Dynamics CRM 2011中访问window.parent的Xrm.data.entity对象 - Unable to access window.parent's Xrm.data.entity object from a opened frame web resource Dynamics CRM 2011 无法通过Chrome从aspx页面使用“ parent.window.xrm.page”访问ms crm页面 - Not able to access ms crm page using “parent.window.xrm.page” from aspx page through chrome 如何从IFrame中访问CRM Form Javascript Web资源? - How to access CRM Form Javascript Web Resources from within IFrame? 使用Xrm.Navigation.openWebResource()后如何从Web资源取回表单数据 - How to get back form data from Web resource after using Xrm.Navigation.openWebResource() 从 Xrm.Page 删除后表单中托管的 WebResource 从上下文访问 - Accessing From Context From WebResource Hosted In Form Post Xrm.Page Removal 如何从Microsoft Dynamics CRM表单到html Web资源获取价值 - how to get value from microsoft dynamics crm form to html web resource Xrm.Page.getAttribute()是否可以返回null? Crm 2011 - Could Xrm.Page.getAttribute() return null? Crm 2011 Dynamics CRM:在Eclipse中使用Xrm.Page库 - Dynamics CRM: using Xrm.Page library in Eclipse
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM