Thursday, March 12, 2009

Using window.opener to refer to Parent CRM window's field

There are many ways you could go to the parent CRM window, but this is what I prefer. At first, I followed the SDK example, but then I invented my own. You could follow the SDK if you will?

Even though it is a little JavaScript but the challenge here is to know if the parent window is the one YOU are looking for?

So here is a little chunk of code that confirms you the Parent Window.

if(window.opener) //checks if current window has a parent window
{
   var oParentForm = window.opener.parent.document.getElementById('crmForm');
   if(oParentForm) //This confirms if the parent window is a CRM form
   {
      // Now try to access a field in the parent form
      // like name attribute in Account entity
      if(oParentForm.all.name) //This ensures you have reached the form you're looking for
      {
         // Proceed with your code
      }
   }
}
There could be other methods too, like checking the Object Type Code of the parent form instead of the 'name' field.

More ideas are welcome, don't hesitate, but share.

No comments:

Post a Comment