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 Name | Field Type | Schema Name |
---|---|---|
Entity Name | Single Line of Text | jack_entity |
Field Name | Single Line of Text | jack_field |
Counter | Whole Number | jack_counter |
Increment Unit | Whole Number | jack_incrementunit |
Number Formatter | Single Line of Text | jack_numberformatter |
Prefix | Single Line of Text | jack_prefix |
Suffix | Single Line of Text | jack_suffix |
Prefix Separator | Single Line of Text | jack_prefixseparator |
Suffix Separator | Single Line of Text | jack_suffixseparator |
Prefix Type | Option Set | jack_prefixtype |
Suffix Type | Option Set | jack_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