Record Auto-Numbering in Microsoft Dynamics CRM 2011

on Saturday, 27 April 2013

In this article I am going to show you, step-by-step, how to auto-number your records in Microsoft Dynamics CRM 2011.

* This article assumes you already have your environment set up.


  • First, create a new solution with a name of your choice (I've called mine "JacksSolution").
  • Create an option set in the solution called 'Prefix & Suffix Options', and give it the following options:

Option Set Options
Free Text
2-Digit
4-Digit

  • Create a new entity called 'Auto-number'.
  • Create the following fields on the entity:

Display NameField TypeSchema Name
Entity NameSingle Line of Textjack_entity
Field NameSingle Line of Textjack_field
CounterWhole Numberjack_counter
Increment UnitWhole Numberjack_incrementunit
Number FormatterSingle Line of Textjack_numberformatter
PrefixSingle Line of Textjack_prefix
SuffixSingle Line of Textjack_suffix
Prefix SeparatorSingle Line of Textjack_prefixseparator
Suffix SeparatorSingle Line of Textjack_suffixseparator
Prefix TypeOption Setjack_prefixtype
Suffix TypeOption Setjack_suffixtype

  • Arrange the fields neatly on the form, like so:

  • In this example we are going to automatically number the Invoice entity, so go to the Invoice entity, add a field called 'Invoice ID' of type single-line of text and place it somewhere obvious on the form.
  • Now, create a new JavaScript web-resource with a name of your choice and add the following JavaScript from the linked file to the file in CRM:

  • Go back to the Auto-number entity and call the AutonumberOnLoad function on-load of the form.
  • Also add the OnPrefixSuffixTypeChange function to the on-change event of both the 'Prefix Type' field and the 'Suffix Type' field and pass in the name of the calling field in string format as the parameter (in my case 'jack_prefixtype' and 'jack_suffixtype').
  • Create a new auto-number record in the system and fill in the details, I used the following:

  • Now comes the plugin itself, you will have to create one for each entity you wish to automatically number.  
  • For this example, create a new plugin to fire pre-operation on-create of the invoice entity and add the code found in the following text file:


  • Deploy the plugin to the auto-number solution.
  • Now, create a new invoice and hey-presto, its been numbered!

This component can be easily modified to work with any entity in the system, including custom entities.

0 comments:

Post a Comment