Auto Number in Dynamics 365 Plugin or Dataverse plugin
Dataverse already having a AutoNumber data type which we can use to generate auto number for our tables field. But if for some reason if you want to implement Auto Number generation for tables then you can write a plugin which will do the work for you.
It requires a configuration table to store current counter number and some dummy fields to add update lock.
Step: 1- Create a configuration table with be
Create a configuration table with 3 columns such as Current Number, Note and Rule all text data type.
Add a record with below data in the configuration table. Initially keep the current number as 0. as the counter will start from zero.
Step-2 : Add a text field in target entity
In the target entity lets say Revenue add a new field which will display the auto number.
Now write a plugin using below code. AS we have to use UPDATE LOCK to ensure uniqueness so update your code with your own tables. The plugin code is given below.
Now register the plugin in Post operation of target entity.
after that test the form. Create a revenue the revenue id will auto generate.
Also after this the configuration table gets updated with current value. The fundamental is the configuration table will store the latest counter for the target entity record and we read the value and add by one then update the counter.
Hope it helps.