Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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. The field is an attribute of the contact entity. Here is the HTML web ressource:

<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

The problem is that the getAttribut returns null despite the field of the entity that I want to get. It's always undefined Someone has an idea ?

like image 517
Hubert Solecki Avatar asked Nov 14 '25 18:11

Hubert Solecki


1 Answers

GetGlobalContext function and ClientGlobalContext.js.aspx (client-side reference)

Use the GetGlobalContext function when programming with web resources to gain access to context information. To get the GetGlobalContext function in your HTML web resource, include a reference to 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.


Couple more suggestions:

Webpage (HTML) web resources

Try dropping window from window.parent.Xrm.Page.

An HTML web resource added to a form can’t use global objects defined by the JavaScript library loaded in the form. 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. 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.

Use IFRAME and web resource controls on a form

Try passing inputs from form script.

For webpage (HTML) web resources, use the setSrc method to manipulate the querystring parameter directly.

In an HTML page, the parameters can be accessed by using the window.location.search property in JavaScript.

Sample: Pass multiple values to a web resource through the data parameter

like image 73
James Wood Avatar answered Nov 17 '25 10:11

James Wood



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!