Share via


How to override the CRM 2011 popup alert in CCA when redirecting a popup *Update*

This is an update to a prior blog post here

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:

image

So how do you get rid of it?

The 2 approaches I'm going to describe here work for CRM 3 and 4.0 and CRM 2011.

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.
If you do choose to ignore this warning and go there, be aware that patches and updates to the CRM 2011 platform will most likely overwrite the file you changed and you will find that you need to make a manual update every time.

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.

This is updated from the prior post and I'm updating his new approach here with his permission.

To do it, First you need a web application adapter, you can start one using the Visual Studio templates provided (CCA R1/CRM4 here) (CCA R2/CRM2011 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:

    1: public override bool Initialize()
    2: {    
    3:     bool bRlst = base.Initialize();    
    4:     this.Browser.DocumentComplete += new EventHandler<Controls.DocumentCompleteEventArgs>(Browser_DocumentComplete);
    5:     return bRlst;
    6: }

This will set up our event direct connection to the IE Instance’s Document completed event, at a lower level then what CCA works with normally.

Updating the function on the fly.

Next we need to build out the event handler we created, which will be called when any part of the document raises a document complete event and overwrite the in memory version of the CRM handle popup blocker error function.

That event will look like this:

    1: void Browser_DocumentComplete(object sender, Controls.DocumentCompleteEventArgs e)
    2: {
    3:     IWebBrowser2 browserFrame = e.pDisp as IWebBrowser2;
    4:     if (browserFrame == null)
    5:         return;
    6:     try
    7:     {
    8:         ((mshtml.HTMLDocumentClass)browserFrame.Document).parentWindow.execScript("handlePopupBlockerError=function(url) {}", "javascript");
    9:     }
   10:     catch{}
   11: }

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 makes no guarantee the method name will not change.

This has been used and works successfully on CRM 3, 4 and 2011.

Comments