auto-number

There is a new feature in V9 that allows us to define a field type as “auto-number.” As a few Microsoft Dynamics 365 commentators have noted, there is no way as yet to set a field as auto-number from the UI. It must be done using the API.

For more information, see Microsoft’s documentation at: https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/create-auto-number-attributes.

There are a few installable solutions and external tools available that can do this for you, but that is outside the scope of this blog. Today, we’re talking about some of the things we’ve learned about the behavior of auto-numbered fields when importing data or solutions.

  • Early descriptions of the feature indicated that it was necessary to define a field as auto-number as it was being added to the schema. However, experimentation has shown that it is possible to add the feature to an existing text field. This means that you can add auto-numbering to a text field that already exists in your Org – you don’t need to deprecate the field and use a new one, or go through the tedious process of removing dependencies, dropping the field, re-adding it with the new data type and putting the dependencies back in.
  • V9 Auto-number fields are text fields with an additional property indicating that they are to have auto-numbering applied.
  • Adding this property does not affect any data in existing records. But it does make the field read-only. Any new records will be assigned a value by the built-in auto-number plugin. The auto-number plugin runs pre-create on the creation of a new record.
  • If you import a solution from an Org that has a field defined as auto-number into a D365 Org in which the same field is defined as plain text, it will add that property and the field will be updated to auto-number.
  • However, if you import a solution from an Org that has a field defined as plain text into an Org in which the same field is defined as auto-numbered, it remains auto-numbered and none of the numbering is affected.
  • Importing an auto-numbered field into a new org restarts the numbering sequence for seeding at the default of 1001 for the next added record. This occurs whether it is a new or updated field – it uses the database “sequence” function, and the solution has no awareness of the last used number in the source D365 Org. For more information on this, see the details under Set Seed Value in the Microsoft documentation referenced above.
  • If Imported records have data, they will retain the same value that they are brought in with. If there is no data in the field (either brought in with no data in the CSV or if the field is not present), they will be assigned sequence numbers when imported.
  • There is no guarantee that the numbers applied are unique. If a pre-existing record has a number that will be assigned by the feature at some point in the future, the feature will apply that number. If a record is imported with a value in the sequence number field that is also present in the database, it will generate a duplicate number (unless you defined the auto-number field as an alternate key).

Hopefully, you find these learnings helpful. Don’t forget to subscribe to our blog for more Dynamics 365 tips and tricks!

Happy D365’ing!