PEC200 refers to my content dataset
@gergemina Thanks and PEC200 is the dataset as it relates to the user in your example?
Hi,
I want to display the unique id in my Textbox field on page load.
for eg
ABC/PRR remains the same,
0001 goes on incrementing,
2021 should change once the year changes.
please help me with this.
Hello @gergemina . I was reading through the posting and did not know if anyone told you that a unique ID is automatically generated for you every time you submit the information into PEC200. In the content manager on the top left you will see a button showing ‘4 Hidden Items’. Click on it, then scroll down the list till you see ‘T ID SYSTEM’. This is a system GUID which is automatically created every time you insert a new record into PEC200. Just click on the slider to the left of it, and it will turn on and be displayed in your list of fields. It is automatic, you can’t disable it because it is a SYSTEM generated value. You can just hide it. It is guaranteed to be unique for every new record inserted.
I just reread through your post and saw that you don’t want to use the System GUID.
I have accomplished this is by creating a separate collection to track unique IDs. I called it something like autonumberIDs. In this collection, I have several numeric fields that I track a unique number for every collection that I need a unique ID for. This collection only has 1 record. This is much faster since you only have to deal with one record.
The approach suggested to you above, has you reading through all the records in PEC200, then sorting them in descending order by ID, then grabbing the first one. This is much slower and continues to get more slower the more records you add to PEC200.
With my approach, every time you insert a new record into PEC200, you :
- read the single record from autonumberID
- get the appropriate ID you are tracking for PEC200 and add 1 to it
- write the updated ID back to autonumberID
- take this updatedID and add it to your PEC200 fields
- insert the PEC200 fields into PEC200
These steps would be performed in your beforeInsert function.
There is a very small chance that you could get a duplicate number, if somehow 2 people were concurrently submitting new information at the exact same instant in time.
This makes it much faster than trying to read your whole collection and order it descending.
If you like this and think it the best answer, you can vote for it.
You should create a new post to address your question, since you question is not the same as Georgie’s, even though the solution could be applied to your situation as well.
This thread is old, and will be closed, if you have other questions/concerns please open up a new thread instead of bumping up old ones, it’s against the community guidelines to do so.