In CRM 4.0 developers sometimes needed to extract data from the parent form of a record opened from one of the associated views attached to the record. A contact record opened from an Account would be a perfect example.
Well, CRM 2011’s JavaScript object model is slightly different so using the following technique doesn’t work:
window.opener.parent.document.crmForm;
The variations I located may resemble these:
- window.opener.parent.document.crmForm
- window.opener.document.crmForm
- window.opener.parent.crmForm
Rhett Clinton and I ( along with input from others ), spent a great deal of time trying to figure this out but it was Rhett who finally made the breakthrough.
Here is how it is done within CRM 2011:
window.top.opener.parent.Xrm.Page
We’ve both added this scenario to our JavaScript conversion tools:





[...] morning everyone! just saw this from Mitch Milam. I think it is a must have tip. [...]
Can you give an example of what you might do with this – for us wanna-be-developers?
Jane,
You are on the contact form and need to reach back to the arent account to pull data, say from the address fields or phone numbers or something, to populate similar fields on the contact.
Mitch
Hi,
I'm having a problem using this in a form I open with the "Window.open(…)"-function. I'm getting an "Undefined" error… So when i'm trying to acces the Parent's Entity Name, I'm getting the following error :
Error – MEssage :
There was an error with this field's customized event.
Field:ave_operationsofficerid
Event:onchange
Error:'window.top.opener.parent.Xrm.Page.data.entity' is empty or not an object.
My "JS"-Code :
//if ((window.top != null) && (window.top.opener != null) && (window.top.opener.parent != null) && (window.top.opener.parent.Xrm != null) && (window.top.opener.parent.Xrm.Page != null) && (window.top.opener.parent.Xrm.Page.data != null) && (window.top.opener.parent.Xrm.Page.data.entity != null)) {
if (window.top.opener.parent.Xrm.Page.data.entity.getEntityName() == "contact") {
….
}
//}
The above code works like a charm when opened in a "Form" opened by clicking on the "New" button of an entity in Contact. When I open the same "URL" or a random "URL" with "JavaScript", using the "Window.open(…)"-function, it doesn't work anymore. Is there something I need to do to make it work with the "Window.open(…)". This is crucial when using a "Custom" webpage, where we need to refresh the parent or some fields of the parent.
Kind Regards,
Frederic
This process is designed to be called from the child form of a parent. Say for instance, opening or creating a Contact from the Contact's parent account.
Both have to be on the screen at the same time.
I have no idea what would happen if you use a window.open from JavaScript but I think the issue you are facing is it can't find the Xrm.Page element of the parent form.
Hi,
just FYI, working solution for me is window.top.opener.Xrm.Page,
e.g. window.top.opener.Xrm.Page.data.entity.getEntityName()
Without the 'parent' object in this chain.
Current version of CRM 2011. Basic CRM forms are containing more iframes, so maybe there is a difference.
[...] Accessing the Parent Form from a Child Form Calling External Webservice with Javascript Asynchronously Close MS CRM 2011 Form without Prompt Dynamically Show Different Form onLoad Enable Disable Notes Control Events in onSave method (List of event.Mode) Excessive Sub-Gridding for more than 4 Filtered Lookup for "Add Existing…" Button of a CRM N:N View Get Current User ID and Name Get Selected Record Guid from a Subgrid Link two subgrids on a form together (parent-child-grids) Pass Microsoft Dynamics CRM Data From a Page as a Parameter to Ribbon Actions Populate Lookup Field with String Value (without GUID) using Automatic Resolution Showing Custom Form Alerts Update records of a Sub-grid using OData JSON JQuery Filed under: CRM 2011, Uncategorized [...]
[...] Accessing the Parent Form from a Child Form Calling External Webservice with Javascript Asynchronously Close MS CRM 2011 Form without Prompt Dynamically Show Different Form onLoad Enable Disable Notes Control Events in onSave method (List of event.Mode) Excessive Sub-Gridding for more than 4 Filtered Lookup for "Add Existing…" Button of a CRM N:N View Get Current User ID and Name Get Selected Record Guid from a Subgrid Link two subgrids on a form together (parent-child-grids) Pass Microsoft Dynamics CRM Data From a Page as a Parameter to Ribbon Actions Populate Lookup Field with String Value (without GUID) using Automatic Resolution Showing Custom Form Alerts Update records of a Sub-grid using OData JSON JQuery Share this:EmailDiggRedditStumbleUponTwitterFacebookPrintLinkedInLike this:LikeBe the first to like this post. Posted in: CRM 2011, Uncategorized ← Another blogger (Srikanth Reddy) copies CRM blog posts Be the first to start a conversation [...]