Resolved : Permission Denied error while accessing OrganizationService.svc from JavaScript in CRM 2011

Hi,

I was getting the Permission Denied error in one of our JavaScript that was making Ajax call to OrganizationService.svc. Obviously it was because of some cross domain thing. The problem was that it was working fine in one of our organization but gave error when deployed it in a new organization.

Intially using the below code to set the organization service url

var pagecontext = Xrm.Page.context;

var serverUrl = pagecontext.getServerUrl();

var serviceUrl = serverUrl + “/XRMServices/2011/Organization.svc/web”;

Changing it to following resolved the issue for us

var serverUrl = document.location.protocol + “//” + document.location.host + “/” + Xrm.Page.context.getOrgUniqueName();

var serviceUrl = serverUrl + “/XRMServices/2011/Organization.svc/web”;

Hope it helps

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s