cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
mvdb
Advocate I
Advocate I

Reset autonumber each year (if possible via script that searches in dataverse)

I have a autonumber fielde with as prefix the current year and the sequence are 4 digits starting with 0001. Next January, the prefix will change and the first autonumber of the year will be 2022-0210, but I want it to reset to 0001 so the autonumber will be 2022-0001. I've read that there is no standard solution for this. I've read something about external tools like North52 or Auto Number Manager. On the other hand I'm thinking of writing an OnLoad-script that searches if there are already existing records made in the current year and fill in a custom autonumber of reset the seed while using the script. But for this I'll need to access the Dataverse-tables from within the form(-script) and I don't know how to do this at the moment.

 

What method would be easiest, and how should I tackle this problem? And how can I search in dataverse-tables from within a form-script? Thank you.

1 ACCEPTED SOLUTION

Accepted Solutions
EricRegnier
Super User
Super User

Hi @mvdb,

I wouldn't go the JavaScript route for these main reasons:

  1. you still want the auto number to be set if the records are update outside the main form
  2. you can't guarantee uniqueness of your auto number (e.g. 2 records are open at the same time might have the same number)
  3. as your table grows it wouldn't scale well as the loading time of your form will increase to look at all the records.

The out-of-the-box auto numbering feature will not allow you reset the seed/count. You need to handle this in a custom method with sync plugins and ensure uniqueness by locking the row until the new auto number is updated and committed. High-level logic:

  1. Have a separate table/entity (i.e named AutoNumberConfig) that keeps track of the current sequence, year and a lock column/field.
  2. In the auto number plugin, 1st thing is to update the lock field (generate a new guid) in AutoNumberConfig record. This will lock the row so if another record is created at the same time will wait until this row is done.
  3. Then in you auto numbering logic, check if the current year is different from the last save year. If so reset the sequence otherwise increment the sequence.
  4. Save current record with the auto number and AutoNumberConfig row with the year and sequence.

Here's a good article explain how to achieve this: https://us.hso.com/blog/how-to-implement-robust-auto-numbering-using-transactions-in-microsoft-dynam... 

Hope this helps!

 

View solution in original post

2 REPLIES 2
dpoggemann
Super User
Super User

Hi @mvdb,

 

I have done a similar approach with other customers and really accomplished this in a different way.  I utilized the auto-number fields as they are and utilized a separate field (many times the default Name field) on the table and set this value based on other fields with real-time workflows.  This allows me to have that field change over time if specific values change that drive the value in the unique identifier.

 

The real time workflow approach will execute any time the values change or the record is created.

 

Hope this helps!  Please mark accepted if answers your question or like if helped.

 

Thanks,


Drew

 

EricRegnier
Super User
Super User

Hi @mvdb,

I wouldn't go the JavaScript route for these main reasons:

  1. you still want the auto number to be set if the records are update outside the main form
  2. you can't guarantee uniqueness of your auto number (e.g. 2 records are open at the same time might have the same number)
  3. as your table grows it wouldn't scale well as the loading time of your form will increase to look at all the records.

The out-of-the-box auto numbering feature will not allow you reset the seed/count. You need to handle this in a custom method with sync plugins and ensure uniqueness by locking the row until the new auto number is updated and committed. High-level logic:

  1. Have a separate table/entity (i.e named AutoNumberConfig) that keeps track of the current sequence, year and a lock column/field.
  2. In the auto number plugin, 1st thing is to update the lock field (generate a new guid) in AutoNumberConfig record. This will lock the row so if another record is created at the same time will wait until this row is done.
  3. Then in you auto numbering logic, check if the current year is different from the last save year. If so reset the sequence otherwise increment the sequence.
  4. Save current record with the auto number and AutoNumberConfig row with the year and sequence.

Here's a good article explain how to achieve this: https://us.hso.com/blog/how-to-implement-robust-auto-numbering-using-transactions-in-microsoft-dynam... 

Hope this helps!

 

View solution in original post

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Users online (1,273)