Quantcast
Viewing all articles
Browse latest Browse all 7

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 );                
}
 }
}
}

}
}


Image may be NSFW.
Clik here to view.
Image may be NSFW.
Clik here to view.

Viewing all articles
Browse latest Browse all 7

Trending Articles