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.
I'm not 100% sure, but I can see a couple of problems.
1. I don't think you are using ClientGlobalContext.js.aspx
correctly
I don't think you should be usingwindow.parent
.
I think you should using GetGlobalContext
which returns Xrm.Page.context
.
For example; GetGlobalContext.getServerUrl()
2. getServerUrl()
is deprecated
Use getClientUrl()
instead.
3. I don't believe GetGlobalContext
gives you access to Xrm.Page.data.entity
anyway
GetGlobalContext
only gives Xrm.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).
Use the getValue method on the attributes that contain the data that
you want to pass to the other website, and compose a string of the
query string arguments the other page will be able to use. Then use a
Field OnChange Event, IFRAME OnReadyStateComplete Event, or Tab
TabStateChange Event and the setSrc method to append your parameters
to the src property of the IFRAME or web resource.
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.
If you are opening a modal dialog, then you will not be able to access the parent Xrm context - you will need to pass the values in and then when the dialog is closed, update based on the result.
If you are opening a non-modal dialog then you can use window.opener
Reference: Scott mentioned in community thread
Otherwise, send the record Id & Retrieve again in popup window using soap/odata/webapi.
Solution was to use XrmServiceToolkit. I was trying to update the parent page’s Xrm.data.entity
from child page that was opened using showModalDialog
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: