How to override the CRM 4.0 popup alert in CCA when redirecting a popup.
How to stop the CRM Popup alert when you grab a window and re-host it to another tab, while suppressing the OnNewWindow event is a common issue that developers working with CCA have..
If you tried to suppress a CRM popup and redirect it… you've probably seen this message a few times:
So how do you get rid of it?
The 2 approaches I'm going to describe here work for CRM 3 and 4.0 only, they have not been tested or tried on CRM 2011, IE: Test before you commit.
The most common and direct method is to modify the CRM server side javascript lib that generates the alert.
However, I’m not going to name which JavaScript file it is or were it is as its highly unsupported to do so, and you should avoid doing that if you can.
In short. Please do not do this.
The way the CCA MCS team does this allows CRM to continue without server side changes and works for CRM UI elements hosted inside UII via a WebApplication adapter.
So how do we do it?
We overwrite the in-memory copy of the JavaScript method that generates the popup alert, which is effectively doing the same thing as the server side change, however it only impacts CCA , this approach was developed by a peer of mine in MCS.
To do it, First you need a web application adapter, you can start one using the Visual Studio templates provided here, or if you already have one, you can use it.
Setting up the event hooks:
In your web application adapter you need to override the Initialize method and add in a new event hook for Document complete, this event hook is a lower level event hook then what you would get with the Adapters version of Document complete and should only be used for this purpose.
Code:
public override bool Initialize()
{
bool bRlst = base.Initialize();
this.Browser.DocumentComplete += new EventHandler<Microsoft.Uii.Csr.Browser.Web.DocumentCompleteEventArgs>(Browser_DocumentComplete);
return bRlst;
}
This will set up our event direct connection to the IE Instance’s Document completed event
Updating the function on the fly.
Next we need to build out that event handler, what when called will overwrite the in memory version of the crm handle popup blocker error function
private void Browser_DocumentComplete(object sender, DocumentCompleteEventArgs e)
{
try
{
IWebBrowser2 kllPopupAlert = e.pDisp as IWebBrowser2;
((HTMLDocumentClass)kllPopupAlert.Document).parentWindow.execScript("handlePopupBlockerError=function(){}", "JavaScript");
}
catch { }
}
When this event is called it will run a JavaScript command that will overwrite the in memory handlePopupBlockerError function, have it do ‘nothing’
The net result is that you will not get the popup blocker alert from CRM.
Few cautionary notes: ( disclaimers )
Changing the behavior of CRM is an unsupported modification.. so if you encounter errors in CRM, make sure disable this event and validate that the error is still there prior to calling support on it.
Future updates may change the name of the method that we update here. While that is unlikely, this is an unsupported on the fly modification. The CRM team is not required to guarantees the method name will not change.
This has been used and works successfully on CRM 3 and 4, this has not yet been run against CRM 2011..
Enjoy!
Comments
Anonymous
January 19, 2011
Hi, Thanks for your article. Could you please explain the above scenario in case of Windows Application Thanks in advance. Best Regards, AlimAnonymous
February 11, 2011
Thanks for sharing both the options even when the first one is not supported.Anonymous
July 12, 2011
Hi., Good Article. Can you explain how to open pop window with a tab in windows application..?