Everybody is quite familiar with the Add or Find Person functionality under Lead. Here we get a link under Person details saying Add or Find Person. Clicking this link will open a pop up to fill in the details of the person and new person is created in no time. As soon as we save the data the screen redirects back to summary page with Select Person button. Clicking this button closes the pop up window and sets the person created under Lead person details.
We had a requirement stating the similar functionality explained above for custom entity. We provided the link similar to that of lead entity on our custom entity Person details. Clicking this button we managed to open new person entry form populating all the values by default with no problem. Thanks to my post on pop window handling http://sagecrmaddons.blogspot.com/2010/06/javascript-popup-window.html :-)..
Now here the hitch is, when we open popup window in edit mode and on save of the details set the value on parent page, it’s quite easy task as here we can use the below script to refer parent window objects.
window.parent.document.EntryForm.
Now what do we mean by Parent in above statement? As per the JavaScript concept, parent of the current page is the page from where we come to the current page i.e. an immediate parent.
Now if I have a page in edit mode which redirects to summary page after saving details, the parent of the page i.e. an opener window is lost and the editable screen becomes new parent. Due to this we won’t be able to get the object of the page from where we opened this window. Now how do we set the value of field on parent window then? Well, you just need to change above line of code to following.
window.opener.document.EntryForm.
Using opener will get you the object of opener page wherever you redirect in your popup window. The same phenomenon explained above for pop up window also works for IFRAMES as they are also the child windows and work in similar manner.