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


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 + “//” + + “/” + Xrm.Page.context.getOrgUniqueName();

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

Hope it helps


Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s