I needs some tips on this one, since I couldn’t find anything on this, though it’s probably pretty simple to do, but I can’t think of a way.
Ok, so I need a hidden field which will automatically compute so called id numbers for every document, the numbers must start from 00001 and forward and must never ever repeat. For instance i create a document with numberId = 00001 and another document which creates numberId = 00002, if I ever delete the first or second document, the third created document should have numberId = 00003. No matter how many documents get deleted, the next document created should get the latest numberId and add 1 to it.
I hope I was clear about what I need here. I need an advice or a tip on how would I achieve this.
Also, I can’t use @Unique.
Here is the code that you will need based on some of the comments to the question.
As you can see it first gets the next sequential number in a synchronized block, adds one to it and then puts the number back into the applicationScope.
Then it converts it to the string, adds the additional 4 zeros and then the right 4 characters from it. This returns a string and needs to be stored in a text field. You cannot store it in a number field because Notes will automatically drop the leading zeros from the value.
You can test this function by adding it to a server side javascript library and then including it in a simple page that runs a repeat control to repeat a computed field that just calls the function. Here is my test page.