Home > CRM, CRM 2011 > How to populate a parent form lookup field value in a child form without using fetch xml in CRM 2011

How to populate a parent form lookup field value in a child form without using fetch xml in CRM 2011

If we want to retrieve data of a lookup field of parent form in a child form lookup field then we can use very easy javascript code without fetch xml in CRM 2011.

Let your parent form entity be Case(Incident) in which we need to retrieve a field name Customer of type   lookup (Having two types of values i.e. contact and account) in this lookup field.

The child  entity name casetask   having 1:N relationship(Case to Case task) and  Casetask entity has a lookup field of  Customer Contact in Casetask form so we can retrieve the custtomer data which is filled in Case entity(Customer field)  in the Casetask entity (Customer Contact  field )

So we can use  following  javascript code.

Define the function SETVALUE()

function SETVALUE()
{
if (Xrm.Page.ui.getFormType() == 1)  //Check if  form is in create mode
{
var oType =crmForm.ObjectTypeCode;
if (window.top.opener.parent != null)
{
if ( (window.top.opener.parent != null) &&
    (window.top.opener.parent != null) &&
    (window.top.opener.parent.document != null) &&
    (window.top.opener.parent.document.crmForm != null)) // Check if parent form is null
{
var parentForm = window.top.opener.parent.crmForm;
if (parentForm.ObjectTypeName == “incident”) // Check if parent form type is same or different
    {
var lookupData = new Array();
var lookupItem= new Object();

if (parentForm.all.new_customerid.DataValue && parentForm.all.new_customerid.DataValue[0].id  ) //Check parent customer id field is not null 
{
var contactname   = parentForm.all.new_contact.DataValue[0].name  ;
lookupItem.id= parentForm.all.new_contact.DataValue[0].id ;
lookupItem.name = contactname ;
lookupItem.entityType = “contact” ;
lookupData[0] = lookupItem;
Xrm.Page.getAttribute(“new_customerid”).setValue( lookupData );                
}
 }
}
}

}
}

Advertisements
Categories: CRM, CRM 2011 Tags:
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: