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/";


Set the server url and the OData service path prior to the OData query as follows.

var ODataQuery= GlobalODataPath +"AccountSet?$select=swmship_FirstName,swmship_Surname&$filter=startswith(Address1_City,'Ca')";

This script can be used with different OData queries in CRM forms.

var serverUrl = Xrm.Page.context.getServerUrl();
var GlobalODataPath = serverUrl + "/XRMServices/2011/OrganizationData.svc/";
var ODataQuery= GlobalODataPath +"AccountSet?$select=swmship_FirstName,swmship_Surname&$filter=startswith(Address1_City,'Ca')";
Advertisement

Author: Indika Abayarathne

MSc in IT [University of Colombo] Solutions Architect | Consultant Technologies: Power Platform | Dynamics CE | Azure

2 thoughts on “Set Server Url to OData Query Dynamically using JavaScripts in CRM 2011 Forms”

  1. Hello, i think that i saw you visited my web site so i came to “return the favor”.
    I’m trying to find things to improve my web site!I suppose its ok to use a few of your ideas!!

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 )

Facebook photo

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

Connecting to %s

%d bloggers like this: