web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

CORS Ajax Request fails in Outlook form but succeeds in web client

(0) ShareShare
ReportReport
Posted on by 40

We are currently using jQuery (1.7) to request data from intranet systems by Ajax from inside the account entity form.

Everything works fine using the web client from IE, Firefox, Chrome in Windows (7) and even Safari on Mac OS X (10.6).

Opening the account form using the Outlook client however fails throwing an "Access denied" error. It seems the request isn't even sent to the server, since we cannot log it using Fiddler or other http logging tools.

Our current setup is: CRM 2011 Rollup 14 (5.0.9690.3557) + Outlook Client 5.0.9690.1992

The failing script looks like this:

           $.support.cors = true;
           $.ajax({
               type: 'POST',
               url: m_serviceUrl + '/json/' + 'CheckAddress?',
               data: JSON.stringify(data),
               contentType: "application/json; charset=utf-8",
               dataType: "json",
               xhrFields: {
                   withCredentials: true
               },
               success: function (result) {
                   completedCallback(result);
               },

               error: function (error) {
                   if (failureCallback == null || failureCallback == 'undefined') {
                       alert("Error: " + error.responseText);
                   }
                   else {
                       failureCallback(error);
                   }
               }
           });

 

The error applies only to forms opened from Outlook, WebResources hooked into the main navigation using the same technique do not have this problem.

*This post is locked for comments

I have the same question (0)
  • DigDug Profile Picture
    40 on at

    Addendum: Using the following IE settings, we could make it work:

    1. Add the CRM server to Trusted Sites.

    2. Edit the Trusted Sties security settings to enable "Access data sources across domains."

    However, this is not an option for our security staff.

    It would be OK if the same applied for intranet sites, but it seems these settings are not respected in the Outlook Add-In.

  • Verified answer
    DigDug Profile Picture
    40 on at

    Answering the own question is always a bit awkward, but OK, here it is.

    We managed to work around this issue by:

    1. Upgrading to jQuery 1.9.1 (which shouldn't be necessary, but we were about to upgrade anyway)

    2. Check for navigator.userAgent containing 'Microsoft Outlook' when initializing the xhr-Object and always use the ActiveXObject('Microsoft.XMLHTTP') in that case

    Starting with row 8454:

    jQuery.ajaxSettings.xhr = window.ActiveXObject ?
      /* Microsoft failed to properly  
    * implement the XMLHttpRequest in IE7 (can't request local files),  
    * so we use the ActiveXObject when it is available  
    * Additionally XMLHttpRequest can be disabled in IE7/IE8 so  
    * we need a fallback.  
    */
    function () { //>> De.Hbv hack for CRM Outlook Client if (navigator.userAgent.indexOf('Microsoft Outlook') > -1) { return createActiveXHR(); } //<< De.Hbv return !this.isLocal && createStandardXHR() || createActiveXHR(); } : // For all other browsers, use the standard XMLHttpRequest object createStandardXHR;

    3. Wrap xhr-Settings in a try/catch block

    From row 8501 (after applying the above)

    // Apply custom fields if provided
    if (s.xhrFields) {
      for (i in s.xhrFields) {
        //>> De.Hbv hack for CRM Outlook Client
        try {
          xhr[i] = s.xhrFields[i];
        } catch(e) {
          // ignore
        }
        //<< De.Hbv
     }
    }
    

    And action!

    Have a nice day

    Markus

  • Suggested answer
    Community Member Profile Picture
    on at

    Yeap. That seems to work. Thank You!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans