Posted on 8. May 2014

Sparkle XRM Code Snippets

If you are doing Sparkle XRM development then you'll find these code snippets I've created for VS2012 very useful. You can grab them from the master repository:
To start using these snippets you simply need to copy the contents of the Snippets directory and paste it into your profile directory at Users\<username>\Documents\Visual Studio 2012\Code Snippets

Using the snippets in Visual Studio is easy – When you are creating a new view HTML page just select all the default code and then type 'sparkle-view-page' followed by TAB. This will add the page snippet and allow you to TAB around the highlighted variable parts of the template which in this case are the name of your Client library (default Client.js) and the name of your View Class:

Once you've finished updating the parameters press Escape to exit the snippet edit.

You can then move the cursor to the line marked <!--TODO--> and add in your form by typing 'sparkle-view-form'. This allows you to enter the name of your view model instance and the title of your form section. Now you're ready to move to the TODO line and add the fields by typing the name of the field snippet and again pressing TAB and filling in the parameters.

Here is a list of all the snippets included:

  • sparkle-view-page – Adds the standard HTML View template
  • sparkle-view-form – Adds the standard Sparkle XRM Form scaffolding
  • sparkle-view-grid – Adds a Sparkle XRM grid
  • sparkle-view-text – Adds a text field
  • sparkle-view-numeric – Adds a numeric field and allows setting the max/min to a constant or view model field.
  • sparkle-view-optionset – Adds a optionset field and allows specifying the entity and attribute to grab the optionset metadata from.
  • sparkle-view-datetime – Adds a datetime field
  • sparkle-view-lookup –Adds a lookup field and allows specifying the search command to return the available records to select. The sparkle-viewmodel-searchcommand can be used to create the search command in the ViewModel Script# code.

There are also some snippets to add a View and ViewModel:

  • sparkle-view-class – Used to create a template view class that is referenced by your html view page.
  • sparkle-viewmodel-searchcommand – Used to create a command that is used to bind to a sparkle-view-lookup to be used when searching within the lookup field.

You'll find that using this snippets will speed up writing your code and reduce errors. Hope it helps!


Comments are closed