Set Server Url to OData Query Dynamically using JavaScripts in CRM 2011 Forms

Following statement can be used to retrieve accounts from the CRM application with the MyOrganization hosted in DevServer.

http://DevServer/MyOrganisation/xrmservices/2011/OrganizationData.svc/AccountSet?$select=swmship_FirstName,swmship_Surname&$filter=startswith(Address1_City,’Ca’)

http://DevServer/MyOrganisation/” part is varried according to the hosted server and the organization and it might raise errors when the above OData query get executed in some other CRM application.

Following JavaScript can be used to get the server url in the CRM 2011 forms.

var serverUrl = Xrm.Page.context.getServerUrl();

Get the next part of the OData service part.

var GlobalODataPath = serverUrl + "/XRMServices/2011/OrganizationData.svc/";

Continue reading “Set Server Url to OData Query Dynamically using JavaScripts in CRM 2011 Forms”