简体   繁体   English

Dynamics CRM 365 - 无法访问HTML Web资源中的Xrm.Page.entity

[英]Dynamics CRM 365 - Cannot access Xrm.Page.entity in HTML web ressource

I've added an html resource in my contact form which contains only an small image in order to place it just beside a contact field. 我在我的联系表单中添加了一个html资源,其中只包含一个小图片,以便将它放在联系人字段旁边。 When the user clicks on it, it fires up a javascript function in which I want to get the value of a specific field of the form. 当用户点击它时,它会启动一个javascript函数,我想在其中获取表单特定字段的值。 The field is an attribute of the contact entity. 该字段是联系实体的属性。 Here is the HTML web ressource: 这是HTML Web资源:

<html>
<head>
    <style type="text/css">
        body 
        {
         margin: 0;
         padding: 0;
         }
     </style>
    <script type="text/javascript">
        function call() {
            var phoneNumber = window.parent.Xrm.Page.getAttribute("mobilephone").getValue();
        }
    </script>
<meta>
</head>
<body style="word-wrap: break-word;">
    <img onmouseover="this.style.cursor='pointer';" src="/webresources/new_/image/image.png" onclick="call()">
</body>
</html>

I have tried also to get data as follows: 我也尝试过获取如下数据:

window.parent.Xrm.Page.data.entity.attributes.get("telephone1").getValue()

But it doesn't work either: cannot read entity of null 但它也不起作用: 无法读取null的实体

The problem is that the getAttribut returns null despite the field of the entity that I want to get. 问题是getAttribut返回null,尽管我想要的实体字段。 It's always undefined Someone has an idea ? 它总是未定义有人有想法吗?

GetGlobalContext function and ClientGlobalContext.js.aspx (client-side reference) GetGlobalContext函数和ClientGlobalContext.js.aspx(客户端引用)

Use the GetGlobalContext function when programming with web resources to gain access to context information. 在使用Web资源进行编程时,请使用GetGlobalContext函数来访问上下文信息。 To get the GetGlobalContext function in your HTML web resource, include a reference to ClientGlobalContext.js.aspx. 要在HTML Web资源中获取GetGlobalContext函数,请包含对ClientGlobalContext.js.aspx的引用。

You can use the GetGlobalContext function when you include a reference to the ClientGlobalContext.js.aspx page located at the root of the web resources directory. 当您包含对位于Web资源目录根目录的ClientGlobalContext.js.aspx页面的引用时,可以使用GetGlobalContext函数。


Couple more suggestions: 结合更多建议:

Webpage (HTML) web resources 网页(HTML)网络资源

Try dropping window from window.parent.Xrm.Page . 尝试从window.parent.Xrm.Page删除window

An HTML web resource added to a form can't use global objects defined by the JavaScript library loaded in the form. 添加到表单的HTML Web资源不能使用由表单中加载的JavaScript库定义的全局对象。 An HTML web resource may interact with the Xrm.Page or Xrm.Utility objects within the form by using parent.Xrm.Page or parent.Xrm.Utility , but global objects defined by form scripts won't be accessible using the parent. HTML Web资源可以使用parent.Xrm.Page或parent.Xrm.Utility与表单中的Xrm.Page或Xrm.Utility对象进行交互 ,但是使用父表单无法访问由表单脚本定义的全局对象。 You should load any libraries that an HTML web resource needs within the HTML web resource so they're not dependent on scripts loaded in the form. 您应该在HTML Web资源中加载HTML Web资源所需的任何库,这样它们就不依赖于表单中加载的脚本。

Use IFRAME and web resource controls on a form 在表单上使用IFRAME和Web资源控件

Try passing inputs from form script. 尝试从表单脚本传递输入。

For webpage (HTML) web resources, use the setSrc method to manipulate the querystring parameter directly. 对于网页(HTML)Web资源,请使用setSrc方法直接操作querystring参数。

In an HTML page, the parameters can be accessed by using the window.location.search property in JavaScript. 在HTML页面中,可以使用JavaScript中的window.location.search属性访问这些参数。

Sample: Pass multiple values to a web resource through the data parameter 示例:通过data参数将多个值传递给Web资源

If you can not take the James Wood solution that is excellent try: 如果你不能采取优秀的詹姆斯伍德解决方案尝试:

1. You must check that your item is in an iframe 1.您必须检查您的商品是否在iframe中

You can get inspired by the following script: 您可以从以下脚本中获得灵感:

Xrm.Page.ui.controls.get('id_iframe').getObject().onload= function() {
    var element = Xrm.Page.ui.controls.get('id_iframe').getObject().contentWindow.document.getElementById('id_element_inside_iframe');
    console.log(element);
};

Xrm.Page.ui.controls.get('id_iframe').getObject(): Returns the HTML object iFrame Xrm.Page.ui.controls.get('id_iframe')。getObject():返回HTML对象iFrame

2. You could have an event called problem. 你可能会遇到一个叫做问题的事件。

You can get inspired by the following script: 您可以从以下脚本中获得灵感:

<HTML>
  <BODY onload="SetupEvents()">
    <label id="myLabel" >Click me</label>
  </BODY>
  <SCRIPT>
      function DoTheThing() {  alert('thing was done');   }
      function SetupEvents() {
          addEvent( document.getElementById('myLabel'),'click', function () { DoTheThing(); });
      }

        function addEvent(element, evnt, funct){
            if (element.attachEvent)
            return element.attachEvent('on'+evnt, funct);
            else
            return element.addEventListener(evnt, funct, false);
        }
</SCRIPT>
</HTML>

I think this is a Turbo Forms issue since Turbo Forms loads Javascript in parallel and loads ClientGlobalContext.js.aspx as one of the last items. 我认为这是一个Turbo Forms问题,因为Turbo Forms并行加载Javascript并加载ClientGlobalContext.js.aspx作为最后一项。 IFrames contain an OnReadyStateCompleted event, I would suggest that you add the following code under that event. IFrame包含OnReadyStateCompleted事件,我建议您在该事件下添加以下代码。

function call() {
            var phoneNumber = window.parent.Xrm.Page.getAttribute("mobilephone").getValue();
        }

See picture below 见下图 ReadyStateComplete

Let's say that your webresource is at root label... then you must add the ClientGlobalContext reference first 假设您的webresource位于根标签处...然后您必须首先添加ClientGlobalContext引用

<script src="ClientGlobalContext.js.aspx" type="text/javascript"></script>

After doing that you should be able to to get the attribute value with your function by just dropping the "window" part first 完成后,您应该能够通过首先删除"window"部分来获取函数的属性值

<script type="text/javascript">
    function call() {
        var phoneNumber = parent.Xrm.Page.getAttribute("mobilephone").getValue();
    }
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 CRM Dynamics:将arraybuffer传递给html Web资源 - CRM Dynamics:To pass arraybuffer to html web ressource 无法从CRM 2011中的HTML Web资源中访问Xrm.Page.data - Cannot access Xrm.Page.data from within HTML web resource in CRM 2011 无法从CRM中的HTML Web资源中访问Xrm.Page.context - Cannot access Xrm.Page.context from within HTML web resource in CRM 无法从打开的框架网络资源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 在Dynamics 365 CRM上使用Xrm Object将表单设置为只读 - Set form read only using Xrm Object on Dynamics 365 CRM 在 Dynamics 365 XRM Web API 中创建记录时无法设置多选选项字段 - Cannot set multi-select option field when creating record in Dynamics 365 XRM Web API MS Dynamics 365-Iframe-Access Xrm-权限被拒绝 - MS Dynamics 365 - Iframe - Access Xrm - permission denied Dynamics CRM:在Eclipse中使用Xrm.Page库 - Dynamics CRM: using Xrm.Page library in Eclipse Xrm.Page.getControl() 在 Dynamics 365 Sales Hub 中不起作用 - Xrm.Page.getControl() not working in Dynamics 365 Sales Hub Dynamics CRM - 如何在 Javascript Web 资源中使用 JQuery - Dynamics CRM - How to use JQuery in a Javascript Web ressource
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM