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)

Cross domain issue with CRM Organization Data service

(0) ShareShare
ReportReport
Posted on by

Hi everyone,

Thanks for helping in advance!

I'm struggled with the following JavaScript code on email entity:

function GetEmailQueueForCase(idCase) {
var strExpand = "$expand=accounts";
var strSelect = "$select=accounts/EmailQueueId";

var req = new XMLHttpRequest();
req.open("GET","http://dynamicscrm.com/XRMServices/2011/OrganizationData.svc/"

+ "/IncidentSet(guid'" + idCase + "')?" + strExpand + "&" + strSelect,
true);
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.onreadystatechange = function () {
GetEmailQueueForCaseCallback(this);
};
req.send();

This function doesn't work if I access the crm through HTTPS protocol : https://dynamicscrm.com/

the error given by crm is access denied 

The code would return error at the req.open line

I did some research and it seemed to be the cross domain issue. Then I tried to use a proxy page to get around it.

I tested the proxy page and it was up and running fine so I put the .ashx file in CRM.

However, when I add it to the code:

var proxyUrl = "https://dynamicscrm.com/DotNet/proxy.ashx?";

req.open("GET", proxyUrl + "http://dynamicscrm.com/XRMServices/2011/OrganizationData.svc/"+
"/IncidentSet(guid'" + idCase + "')?" + strExpand + "&" + strSelect,
true);

It doestn't work. Although the access denied error was not happen, the xmlhttprequest() is not returning the correct data. I'm having a readystate 4 but status 500 situation or a readystate 4 but status 401

I wonder if using proxypage to get data from CRM organization data service is not allowed?

Is there another way around?

Please shed some light on my issue. Thank you very much!!

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Hello,

    Try to use following code:

    req.open("GET","/XRMServices/2011/OrganizationData.svc/"
    + "/IncidentSet(guid'" + idCase + "')?" + strExpand + "&" + strSelect,
    true);


    instead of 

    req.open("GET","dynamicscrm.com/.../OrganizationData.svc"
    + "/IncidentSet(guid'" + idCase + "')?" + strExpand + "&" + strSelect,
    true);


  • Community Member Profile Picture
    on at

    Thank you for your reply! But unfortunately, it didn't work. I'm getting a status 400. I guess if not specified the protocol, the request couldn't consume the organization data service?

  • Verified answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Then try to use following:

    req.open("GET", Xrm.Page.context.getClientUrl() + "/XRMServices/2011/OrganizationData.svc/"
    + "/IncidentSet(guid'" + idCase + "')?" + strExpand + "&" + strSelect,
    true);


  • Community Member Profile Picture
    on at

    thank you very much Andrii, but this is how the original issue comes up. the OrganizationData.svc is using http protocol. However, I need to access crm using https protocol. so if I use get clienturl() under https protocol, it will return https://...organizationdata.svc which will not functioning properly. Therefore, I hardcode in the JavaScript code to use http://...organizationdata.svc under https protocol and encounter the cross domain issue.

    Thank you very much again for helping me. I hope I describe the issue clear enough

  • a33ik Profile Picture
    84,331 Most Valuable Professional on at

    OrganizationData.svc uses the same protocol as CRM app. So your sentence "OrganizationData.svc is using http protocol. However, I need to access crm using https protocol." has no sense.

  • Community Member Profile Picture
    on at

    yes, the crm app is set as http protocal in deployment manager administrator. therefore, in the developer resources, the end point of organization data service is using http. But I need to access crm through https. When I use https to access crm, for example:

    dynamicscrm.com/main.aspx. the getrclienturl() will return back the string start with https as well.  This causes an issue due to the mismatching protocol.

    Sorry if it doesn't make sense.

  • a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Yes. Unfortunately this doesn't make any sense for me.

    I'm really sorry but one your statement conflicts with other. You write:

    "When I use https to access crm, for example:dynamicscrm.com/main.aspx. the getrclienturl() will return back the string start with https as well."

    This is 100% ok. But after you write following:

    "This causes an issue due to the mismatching protocol."

    but this is not truth because both protocols are https. What is "mismatching" in your understanding?

  • Community Member Profile Picture
    on at

    thank you so much Andrii, this resolved my issue at the first place. There was a piece of code in the JS that hard coded the protocol to be http and caused the issue!

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