CRM 2011 – using Javascript intellisense and Testpage.htm

I have been doing some Javascript development this past couple of days and although I have been using the CRM development toolkit it was more focused on plugins rather than writing javascript.

I then noticed a folder in the CRM 2011 SDK called templates and in there was a folder called xrm.pagescriptprojejcttemplate, this has been blogged about by the Microsoft team and you can read their version here or continue reading mine

CRM 2011\sdk\templates\xrm.pagescriptprojecttemplate


There was a readme file with instructions on how to setup the project.

I won’t go through it all here because the readme file does a great job of going through setting up the project step by step.

There are a number of parts to the solution.

It has a visual studio template which creates XmlPageJScriptLibrary project.

This project creates a few pages but the most important ones are


The js script above has the functionality to add intellisense for the Xrm.Page commands.

For any new Javascript files you create you add a reference to this file and then when you type in Xrm you get intellisense for it.

You add the reference by adding the line to the top of your Javascript file

/// <reference path=”XrmPageTemplate.js” />

Now this is one part of the solution, which when you think about it has involved a good work around by the Microsoft team to come up with a solution.

You now have the Xrm.Page intellisense and now you need the intellisense for the entities and especially your entities, so you can access your custom variables you have added to entities.

There is a solution project you need to import into your organisation.

What this does is add a button onto all the Forms in CRM.  The button is XrmPagesnapshot is used to create the snapshot of your form for either onLoad, OnSave or onChange of a variable.

You go to customize on the entity form you want to write some Javascript for, you then press the XRM Page snapshot button.  This pops up a form and you can then copy the code to clipboard.

You then take this code and paste it into a file into you visual studio XRMPAge project into a file called PageData.js

The XrmPage Project has a TestPage.htm which allows you to test your code.

The TestPage is a nice way to test the code quickly.  The snapshot creates the variables in the state you took the snapshot.

So in my case I writing a function to test when a drop down was a certain value.  I could use the the testPage to test my function, it would open the function and the values of the variables would be set to the snapshot.

This means you don’t have to keep uploaded and publishing.

The only downside is we still don’t have proper intellisense for the entites unlike the workaround in CRM 4 –

but its better than nothing.

Also the snapshot code does generate all the variables for you to look at, this means you can see all the variables and their potential values.  Below is dropdown I have with two values, property and person.  Below you can see the values and the int number for the dropdown.  This alone could save you some time.  Combined with the functionality of being able to quickly test this using the testPage.html makes Javascript development a bit easier.

{ “Name”: “meta_contacttype”, “Value”: 951850000, “Type”: “optionset”, “Format”: null, “IsDirty”: false, “RequiredLevel”: “none”, “SubmitMode”: “dirty”, “UserPrivilege”: { “canRead”: true, “canUpdate”: true, “canCreate”: true }, “InitialValue”: 951850000, “Options”: [{ “text”: “Property”, “value”: 951850000 }, { “text”: “Person”, “value”: 951850001}], “SelectedOption”: { “option”: “Property”, “value”: 951850000 }, “Text”: “Property”, “Controls”: [{ “Name”: “meta_contacttype”}] }


Overall I think the most useful part is the XrmPageTemplate.js file which I think you can use even without the whole javascript intellisense project.

The way Javascript works in CRM makes it very difficult to create proper intellisense.  I think what would be useful is perhaps code shortcuts and Javascript validation.


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