Thursday, February 16, 2012

CRM 2011 : Access is Denied error message in Rest Query

This appear when you use an IP address or localhost in CRM Url. The reason is that your REST query uses the server name from the context.getServerURL function. When you make a request to what is interpreted as a different domain you will get an error.

You might try putting your IP address in your Internet explorer trusted sites and then change the IE options to allow cross domain requests, but the simplest solution is to just use the server name when you open Microsoft Dynamics CRM.

The following workaround use the application server name:


Workaround


var serverURL;

try{
serverURL =  getServerUrl()  
}catch(error e)
{
serverURL = document.location.protocol + "//" + document.location.host + "/" + Xrm.Page.context.getOrgUniqueName();
}





Thanks,
Nicola

1 comment: