Dynamics Crm 365 - Cannot Access Xrm.page.entity In Html Web Ressource
Solution 1:
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:
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
Solution 2:
If you can not take the James Wood solution that is excellent try:
1. You must check that your item is in an 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
2. You could have an event called problem.
You can get inspired by the following script:
<HTML><BODYonload="SetupEvents()"><labelid="myLabel" >Click me</label></BODY><SCRIPT>functionDoTheThing() { alert('thing was done'); }
functionSetupEvents() {
addEvent( document.getElementById('myLabel'),'click', function () { DoTheThing(); });
}
functionaddEvent(element, evnt, funct){
if (element.attachEvent)
return element.attachEvent('on'+evnt, funct);
elsereturn element.addEventListener(evnt, funct, false);
}
</SCRIPT></HTML>
Solution 3:
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. IFrames contain an OnReadyStateCompleted event, I would suggest that you add the following code under that event.
functioncall() {
var phoneNumber = window.parent.Xrm.Page.getAttribute("mobilephone").getValue();
}
Solution 4:
Let's say that your webresource is at root label... then you must add the ClientGlobalContext reference first
<scriptsrc="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
<scripttype="text/javascript">functioncall() {
var phoneNumber = parent.Xrm.Page.getAttribute("mobilephone").getValue();
}
</script>
Post a Comment for "Dynamics Crm 365 - Cannot Access Xrm.page.entity In Html Web Ressource"