Friday, October 6, 2017

Auto Number attributes in Microsoft Dynamics 365

With the release of Microsoft Dynamics 365 Customer Engagement October service update (v9.0), two of the most requested customization features were finally implemented in the platform:

  • Multi-select optionsets
  • Custom auto numbered attributes
The first one has full customization features available in the UI out of the box, but to create and manage auto numbering attributes you have to write code utilizing SDK-functions.

This article will describe how to use the Auto Number Manager tool for XrmToolBox giving an intuitive UI to access SDK-only features for auto numbering.


Auto Number Features

The Auto Number attributes support three different types of placeholders – sequential numbers, random text, and date/time in different formats.


Sequential number:

  {SEQNUM:n} where n is the minimum number of digits.

Random text:

  {RANDSTRING:n} where n is the number of characters in the random string. Maximum value for n is 6.


  {DATETIMEUTC:fff} where fff is a standard datetime format string. See documentation.

Other text:

    Any other text may be included in the number format. This text will be used as is.

Sample auto number formats:

  Number Format                                Example value
  CAR-{SEQNUM:3}-{RANDSTRING:6}                CAR-123-AB7LSF
  CNR-{RANDSTRING:4}-{SEQNUM:4}                CNR-WXYZ-1000
  {SEQNUM:6}-#-{RANDSTRING:3}                  123456-#-R3V
  KA-{SEQNUM:4}                                KA-0001
  {SEQNUM:10}                                  1234567890
  QUO-{SEQNUM:7}{RANDSTRING:5}                 QUO-0001000P9G3R
  CAS-{SEQNUM:6}-{DATETIMEUTC:yyyyMMddhhmmss}  CAS-002000-20170913091544
  CAS-{SEQNUM:6}-{DATETIMEUTC:yyyyMMddhh}      CAS-002002-2017091309


Update! XrmToolBox now supports SDK v9.0, so installation of Auto Number Manager is done through the Plugins Store in XrmToolBox.


The Auto Number Manager will be available in the Plugins Store of XrmToolBox once the SDK for Dynamics 365 v9.0 is released and XrmToolBox delivered using that version.

Until then:

  1. Go to the Releases page on the GitHub repository:
  2. Download the ANM zip file (not the source code)
  3. Right-click the downloaded file and select Properties
  4. Tick the “Unblock” checkbox and click OK
  5. Open the zip file and copy all files and folders
  6. Open the folder where XrmToolBox is installed
  7. Paste the files from the zip
  8. Start XrmToolBox

The release package contains two SDK assemblies for v9.0, and a folder Plugins that contains the ANM plugin assembly.

Note: Information on how to install and run XrmToolBox, read the wiki:

Running ANM

Make sure you are connected to an organization with version 9.0 or above. Starting ANM connected to older versions will display an error message.


Opening ANM will load existing unmanaged solutions. Select the solution where you want to manage your auto number attributes.

Selecting the solution will populate a list of entities included in the solution.


Select an entity, and any existing auto number attributes will be show in the table below.

To create a new auto number attribute, click button New Attribute.


  • The prefix of the Logical Name is taken from the publisher of the selected solution, and cannot be changed.
  • Enter Logical Name, Display Name and Description for the attribute.
  • Make sure the Maximum Length is large enough to hold the generated auto number value. If the resulting string is too long, users will not be able to create new records.
  • The Language Id is retrieved from the current user, and is used to define for which language the Display Name and Description shall be created.
  • Number Format is the property where the magic is defined. See syntax and samples above. At the time of writing this article, it is somewhat unclear whether the SEQNUM placeholder should be required, but as this is the most probable definition, this is also implemented in ANM. Clicking the blue shortcuts below the number format will help composing the format.
  • The Seed property can be used to define the next value to be assigned to a new record for the SEQNUM placeholder of the auto number format. The seed can be set when creating a new auto number attribute, and when updating existing attributes.
  • To make it easier to create the Number Format, a Sample Number of the resulting values is displayed on the form.
  • Below the sample number a help text is displayed indicating if the Number Format is correctly formatted, or if there are any errors. This help text will let you know if the Maximum Length property is too small, as well as format errors.

The Techy Stuff


Technically this is not a new attribute type. It is the same old “Single Line of Text” data type, with format “Text”. What has been added is a new property AutoNumberFormat on the StringAttributeMetadata class. This would indicate that existing attributes, both custom and standard, could be decorated with this new property to activate auto numbering for existing attributes. Initial tests succeed in doing that, but this is most probably a missing constraint in this version of the SDK, and should not be possible. ANM does therefore not support this action.


The platform core assigns the automatic numbers by an internal plugin at stage Initial Pre-operation (5). This means that custom plugins of all stages can read the assigned number. Another result of this is that custom plugins have no way of really knowing how the value was assigned – by the internal numbering or by programmatic creation of records.

Sequence counter

The technology behind the actual “counting” is based on the SQL Server SEQUENCE feature. There is currently no way of reading the current or last assigned value of the sequence, other than reading the most recently created record of the entity, and parsing the value of the numbered attribute.


The seed can be set to update the current value of the sequence number. This will, naturally, only affect records created after the seed has been updated. It MAY result in duplicated numbers, if the seed is set to a lower value than current sequence position.

Random characters

At this point it is not possible to define which character set the random string is generated from. This is entirely controlled by the core plugin assigning the auto numbers. But we sure do hope the SDK will be updated to allow us to define exactly which characters that can be included in the random strings!

Read more

After investigating the Auto Number features extensively, I wrote about some More Auto Numbering features.



  1. I tired installing this Auto Number Manager tool for XrmToolBox but I get the below warring when adding from the plugins store. I have installed the latest version of XrmToolBox (v1.2017.7.18).

    "This plugin implements features form latest version of XrmToolBox. Please update your XrmToolBox to latest version to be able to install the plugin version."

    Please advise on possible cause of this warning and ways to troubleshoot it.

    1. Hi Patel,
      The official SDK for v9.0 is not released yet, so installation through XrmToolBox (that still use SDK v8.2) is not possible, that is why the warning is displayed.

      This is not mentioned in this article, but on the ANM webpage you can read the following on how to install it before SDK and XTB is updated:

      Until SDK for v9.0 is released and XrmToolBox updated to use it,
      beta version of Auto Number Manager can be downloaded from

      Let me know if this works or not :)

  2. Hi Jonas,

    I have installed ANM successfully and it works just fine.
    I'm using ANM with my Product entity and it will be used to automatically update the Product IDs when a record is created.
    I have installed the new attribute and ANM has created a new field and it is on my main form for the product entity. When I’m creating a new product, the new field works fine.
    So long, so good ��
    Inside the CRM there is the originally field for Product IDs on my existing products. The product IDs is filled with different values and there is no connection between the different product IDs. For example: one product ID is: Office 365 and next is PO-125499. Obviously, no cohesion between the existing product IDs.
    I’m using this number format: AA-{SEQNUM:5} with seed 1. So the structure are: AA-00001, AA-00002, AA-00003 and so on.
    So, my question is:
    How can I update all my existing products that already has the originally product ID into my new product ID structure on my new field?
    Best regards, Mathias

    1. Hi Mathias - so sorry about slow response time...
      The build-in feature for auto numbering only supports assigning numbers when records are created.
      So I guess you would have to write code to reassign numbers for existing records, and then reset the seed (current number) to make sure you do not get duplicates.

  3. This comment has been removed by a blog administrator.

  4. Hi,

    I created one autonumber field to a custom entity. But when I import the solution to other CRM instance (v 9.0) auto number field does not work on new instance. Am I missing something? Where does/how does CRM manages the auto-calculation/auto-numbering...

    Any suggestion ?

    1. Microsoft have inexplicably not included the auto number format property in the customizations file when exporting a solution.
      This has been reported as a bug, I currently don't have information on when it will be fixed. But please open a support ticket for this - the more tickets they get, the faster it might get prioritized.

      Workaround for now is to apply the same format in target environment after solution is imported.

  5. HI Jon,Thanks for article and I tried through XRM-ANM created date field farmat and updated in my custom entity when I create on new record to create account .Its updating on save not on onload of record creation ..Any help much appreciated ....I working on crm365

    1. Hi,
      This is expected behavior, the Auto Numbering feature works server side, so it will generate the number according to the format when you save the record.