Though Dynamics 365 has OOB feature to enable auto numbering for the system entities (like Case, Opportunity, Lead, Contract etc), most of the times custom auto numbering solution might be required considering the below scenarios:

 

  • Auto number generated by Dynamics 365 doesn’t meet the business expectation [ eg: having alpha numeric values in the auto generated number which is not customer friendly]
  • Auto numbering is required for other system entities or custom entities
  • Auto number generated by Dynamics 365 doesn’t support the integration with other related systems

 

In such cases, we should develop a custom auto number solution:

 

Option 1 [Directly triggering the auto number generation plugin]

  • Custom entity [Sequence] to maintain the format of the auto number and the sequence number
  • Custom plugin [Generate Auto Number] on pre-create of required entity to generate the auto number

 

Option 2 [If creation of business record doesn’t need to wait for the auto number]

 

  • Custom entity [Auto Number Request] to create an auto number request record on creation of the required entity
  • Custom plugin [Create Auto Number Request] to Create an Auto Number Request record on creation of the required entity
  • Custom entity [Sequence] to maintain the format of the auto number and the sequence number
  • Custom plugin [Generate Auto Number] on pre-create of required entity to generate the auto number

 

 

In both options, plugin [Generate Auto Number] should ensure that two records created in parallel shouldn’t have the same sequence. Since there is no lock on ‘Read’ of an entity, there can be two numbers generated having the same sequence number.

 

One way to overcome this is by adding a new dummy attribute in the [Sequence] entity which would be updated by the [Generate Auto Number] before fetching the ‘Sequence Number’ from the [Sequence] entity. When the plugin updates the [Sequence] entity, since the FIRST operation we perform on the sequence record is an update, we have serialized the process.

 

A detailed post on this approach can be checked here: https://www.akaes.com/blog/how-to-implement-robust-auto-numbering-using-transactions-in-microsoft-dynamics-crm/

 

PS: If you don’t want to get in to the complexity of writing custom plugin, you can check out the auto number solution from celadon partners.

https://celedonpartners.com/blog/celedon-autonumber-solution-for-dynamics-crm/

Leave a comment