It is not an uncommon requirement to pull data for from the parent entity of the current record. In many cases, this child entity is only created from its parent so we can simply just reference the window.opener object to get a reference to the parent form.
An example would be creating a new Contact or Order from inside the Account form.
I got tired of writing this code over and over so yesterday I set down to attempt a solution that would be dynamic and I could just call from the Form’s OnLoad event. Here’s my solution:
function GetParentFormFieldValue(fieldName)
{
var retVar = null;
if (
(window.opener != null) &&
(window.opener.parent != null) &&
(window.opener.parent.document != null) &&
(window.opener.parent.document.crmForm != null)
)
{
eval("retVar = window.opener.parent.document.crmForm.all." + fieldName + ".DataValue");
}
return retVar;
}
It is used like this:
crmForm.all.name.DataValue = "New order for " + GetParentFormFieldValue("name");





Hi,
Is there a way to use similar code to get a value from the child entity and enter it into the parent entity?
Many thanks
Aad
Good question Aad, I'm curious about that one too.
Not easily because You can never tell when the child form is open. That means you'll have to go to the database.
Take a look at the Ascentium JavaScript Library:
http://consulting.ascentium.com/blog/crm/Post129.aspx
It will save you tons of time.
Mitch
I found this script incredibly useful thank you