I have a html web resource that has
<script src="ClientGlobalContext.js.aspx" type="text/javascript"></script>
in the head. It is a frame that pops up when a user clicks reject in the ribbon. When I try to click on a reject button in the frame (not the ribbon), it throws the error "Error: Unable to get property 'entity' of undefined or null reference" I know my
window.parent.Xrm.Page.context.getServerUrl()
is working because the lookup frame is populated from our server. I have tried the following :
window.parent.Xrm.Page.data.entity.attributes.get("approvalstatus").getValue()
and
window.parent.Xrm.Page.getAttribute("approvalstatus").getValue();
Both give me errors. I'm totally lost as to why I can't access the parent window's Xrm.Page object. Please advise.
Solution was to use XrmServiceToolkit. I was trying to update the parent page’s
Xrm.data.entity
from child page that was opened usingshowModalDialog
but that doesn’t seem to be possible.XrmServiceToolkit lets you create SOAP requests that allow you to do all CRM operations. Use the format like explained in this link:
Keywords are important.
HTML page within IFRAME in form can access
parent.Xrm.Page.data.entity
Opening frame (popup as dialog/non-dialog?) from Ribbon button, it depends.
Reference: Scott mentioned in community thread
Otherwise, send the record Id & Retrieve again in popup window using soap/odata/webapi.
I'm not 100% sure, but I can see a couple of problems.
1. I don't think you are using
ClientGlobalContext.js.aspx
correctlyI don't think you should be using
window.parent
.I think you should using
GetGlobalContext
which returnsXrm.Page.context
.For example;
GetGlobalContext.getServerUrl()
2.
getServerUrl()
is deprecatedUse
getClientUrl()
instead.3. I don't believe
GetGlobalContext
gives you access toXrm.Page.data.entity
anywayGetGlobalContext
only givesXrm.Page.context
Xrm.Page.data.entity
is a different object.4. I think you should be passing form data into the web resource
This involves you writing JavaScript on the CRM form, that passes values to the HTML web resource.
(As opposed to trying to read the CRM form client side from within the web resource. You could also consider making a web service call from your web resource to CRM as well).