How to show related record’s form in parent form

  • Comments 6
One of my friends was asking how to show related record’s form in its parent form. For e.g. you may want to show primary contact’s form in account form, instead of forcing the user to open the contact form to see the details.

Let’s
see an example. As soon as user selects a primary contact from lookup, we populate contact form in an iframe in account form.Here are the steps to achieve this functionality:
  • Add an iframe in account form & name it IFRAME_primarycontact
  • Write following code in onChange event of the Primary Contact Lookup & onLoad event of the form:
var iframe = document.getElementById('IFRAME_primarycontact');
if
(document.getElementById("primarycontactid").DataValue != null &&     document.getElementById("primarycontactid").DataValue.length > 0) {    var contactId = document.getElementById("primarycontactid").DataValue[0].id;   
iframe.src = window.location.href.replace(window.location.pathname,
"/<org-name>/sfa/conts/edit.aspx?id=" + contactId + "&hideNav=true");
}
else
{    iframe.contentWindow.document.body.innerHTML = "<i>Select Primary Contact</i>";}  

Click here for preview 

We are almost done! The selected contact will now be shown in the iframe. If you want to hide the left navigation pane and top tool bar in contact form, perform following steps:
  • Write following script in onLoad event of contact form:
queryString =  location.search;if(queryString.indexOf("hideNav=true") != -1){    areaFormDiv = document.getElementById('areaForm');    mainTable = areaFormDiv.parentElement.parentElement.parentElement.parentElement;    mainTable.deleteRow(0); // delete top nagivation pane    mainTable.rows[0].deleteCell(0); // delete left navigation pane    mainTable.rows[0].cells[0].colSpan = 2; // span the cell to the entire row}

Click here for preview

Happy Programming! 
  • Wow!Thanks Rameswar Datt, I am strougling for this issue  from last one 1week onwards, now i could able to do it.really it could be great help to me...

  • I’ve often said that I really only do blogs to keep track of projects and learnings for myself.Thanqs ram

  • heay ram,some issues migt not be possible, but it seems possible,yep thanks

  • Good work Ram.....Keep posting good articles....

  • Ram, could you please let me know how to Distribute the CampaignActivity into the WindowsApplication...Thanks

  • I am having an issue while importing my customizations into Production CRM server. I developed a custom entity in my Development server which is having update rollup 10 and now I tried to import those customizations into Production server which is having an Update Rollup 5. After uploading the file, when I tried to import it is throwing a popup with a message title: "Unable to Import or Import failed" and "None" inside the popu body.this is not related to this blog but could you please look into exception but we have a high priority issue with this....Thanks