Retrieving Entity Data Using JScript

This is a step-by-step recipe for retrieving CRM entity data using JScript and the OData (REST) endpoint in an asynchronous manner.

1. Install JScript Editor Extensions  in Visual Studio.

2. Install Visual Studio project template by double-clicking SDK\Templates\XrmPageScriptDevelopmentProjectCS.vsix.

3. Import SDK\Templates\Xrm.PageScriptProjectTemplate\ in CRM.

4. Create a new project and select the Xrm.Page JScript Library Project template.

5. Open an instance of the form, in my case the Quote Product form, and click Xrm.Page on the Customize tab.

6. Click Get Data and then Copy to Clipboard.

7. In your Visual Studio project, replace the contents of PageData.js with the contents of your clipboard.

8. Add a new JScript file called e.g. Product.js with following contents:

/// <reference path=”XrmPageTemplate.js” />
/// <reference path=”SDK.JScriptRESTDataOperations.js” />
function retrieveProduct() {
// This assumes there is a lookup field called productid that contains the selected product.
var lookup = Xrm.Page.getAttribute(“productid”).getValue();
var id = lookup[0].id;
function (product) {
alert(“Retrieved the product named \”” + product.Name + “\”. This product was created on : \”” + product.CreatedOn + “\”.”);

function errorHandler(error)  {

9. In your CRM solution, add the following web resources:

10. Add these web resources as libraries on the form.

11. Add a call to retrieveProduct e.g. on the productid OnChange event.

One thought on “Retrieving Entity Data Using JScript”

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s