JavaScript comes in very handy when working within Microsoft Dynamics CRM, and we have a lot of blogs on using JavaScript in CRM.

crm-2013

Starting from CRM 2011 UR 12, the getServerUrl (which returns the base server URL) and the getAuthenticationHeader method that was available pre-UR12 when referencing the Xrm.Page.context have been deprecated. These two methods are no longer supported in CRM 2013. So if you are referencing the getServerUrl and you are on UR12, and you are upgrading to UR12 or CRM 2013, you need to change all your JavaScript code to use getClientUrl instead.

A good way to make the JavaScript Version agnostic would be to check if the getClientUrl exists before using it.

For example:

var url ;
if(Xrm.Page.context.getClientUrl)//Post UR 12
{
    url = Xrm.Page.context.getClientUrl();
}
else//Pre UR 12
{
    url = Xrm.Page.context.getServerUrl();
}

Take note that getClientUrl does not append the slash character (‘/’) at the end of the URL.

So if you are currently using any JavaScript similar to the snippet below…

var serviceUrl = url + "XRMServices/2011/OrganizationData.svc/";

….make sure you change it to:

var serviceUrl = url + "/XRMServices/2011/OrganizationData.svc/";

If this was helpful, you can also check out our other blogs and resources for Microsoft Dynamics CRM 2013.

Happy CRM’ing!

Avatar for Joe D365

Joe D365

Joe D365 is a Microsoft Dynamics 365 superhero who runs on pure Dynamics adrenaline. As the face of PowerObjects, Joe D365’s mission is to reveal innovative ways to use Dynamics 365 and bring the application to more businesses and organizations around the world.