So I have a form create with various field (connected to database). When a user clicks all the data is stored in database.
However I wish to create a unique ID if any user submits the data. I understand that in order to do so a program needs to sort the data in descending order (by date) and then add +1 to the latest ID.
Can someone help with such a code?
I don’t understand the question.
When you insert a record to your collection, the system automatically creates a unique ID (This field is hidden by default when you open the collection but you can make it visible).
So what are you trying to do? Do you need a different unique ID? Something else?
Yes I need a different unique ID as i need to share these with client for followup of the sales. It shall go into the subject line of the email to the client for the order they have placed.
I am still a bit confused as to how to execute this @J.D. I have created the hook for the data collection, but doesnt seem to be working? Do I need to add a field in the dataset called uniqueId?
This is working in that an id is automatically generated, but the ID does not seem to change for each new entry, it remains as ‘1’ for every entry.
Ie. shouldnt it go up in increments?
That’s because you forgot to change the field key in the query.
You still have there: . descending ( “uniqueId” ) and . distinct ( “uniqueId”
even though you decided to name it “id”. + you haven’t changed the item itself.
It should be:
The code above is for id that is based on running numbers, so it should be numeric.
If you want to include text, you;ll have to make adjustments based on what exactly you want to do.
Im so grateful thank you its working good now. If I was to have the following PEC200-2020-1 and then going up in increments of +1 what would i need to do? Not to worry if this is too complicated!
@jonatandor35 May I jump in and ask for help with this same task?
I’ve created a dataset (allPets) where I want an distinct ID separate from the one the system creates. The data is user-generated via a form, so the numbering needs to be done via a hook.
After I published and tested with a new entry into the dataset, the result was a blank field vs a number (below) instead of the expected 20004. I am not starting the petID numbers at 1, but since it’s sorting in descending order and adding 1 to the last item, I don’t think that’d cause the issue.
had started my site with a canned dynamic page from Wix and built the dataset from there. Although I changed the dataset name throughout to allPets, when I used the hover function to add a hook to it, the hook came back with the original “Team” name for the dataset instead.
I guess I can stop banging my head against a wall now.