Whilst I was developing I had hard coded the serverUrl which I then used whilst doing an oData query.
The quick answer for those of you who have Googled your way to my blog, is you use the Xrm.page.context and use the method getServerUrl(); This will return you the url, including the organisation. After that all you have to do is paste the oData address.
It has three useful parts to it. What I really like is the separation Microsoft has done here, it’s logical and easy to use.
- Xrm.Page.context provides methods to retrieve information specific to an organization, a user, or parameters that were passed to the form in a query string
- Xrm.Page.data provides an entity object that provides collections and methods to manage data within the entity form
- Xrm.Page.ui provides collections and methods to manage the user interface of the form.
Out of the the three the one I use the most is Xrm.page and it has some great methods to get default/organisational information from.
- getAuthenticationHeader: Returns the encoded SOAP header necessary to use Microsoft Dynamics CRM 4.0 Web service calls usingJScript.
- getCurrentTheme Returns a string representing the current Microsoft Office Outlook theme chosen by the user.
- getOrgLcid: Returns the LCID value that represents the Microsoft Dynamics CRM Language Pack that is the base language for the organization.
- getOrgUniqueName: Returns the unique text value of the organizations name.
- getQueryStringParameters: Returns an array of key value pairs representing the query string arguments that were passed to the page.
- getServerUrl: Returns the base server URL. When a user is working offline with the Microsoft Dynamics CRM for Microsoft Office Outlook client, the URL is to the local Microsoft Dynamics CRM Web services.
- getUserId: Returns GUID value of the SystemUser.id value for the current user.
- getUserLcid: Returns the LCID value that represents the Microsoft Dynamics CRM Language Pack that is the user selected as their preferred language.
- getUserRoles: Returns an array of strings representing the GUID values of each of the security roles that the user is associated with.
- isOutlookClient: Returns a Boolean value indicating if the user is using the Microsoft Dynamics CRM for Microsoft Office Outlook client.
- isOutlookOnline: Returns a Boolean value indicating whether the user is connected to the Microsoft Dynamics CRM server while using the Microsoft Dynamics CRM for Microsoft Office Outlook with Offline Access client. When this function returns false, the user is working offline without a connection to the server. They are interacting with an instance of Microsoft Dynamics CRM running on their local computer.
- prependOrgName: Prepends the organization name to the specified path.