Hi, Wix currently creates unique _id for each entry on the database, but i need to display my own ID that increments with + 1 each time a submission is made on a form as this will need to be displayed on Dynamic page at a later stage.
Is there a example or tutorial I can follow?
Help would really be appreciated.
Hi Daniel,
Are you using a “Submit” action of a button of code ?
It is possible with code. you need to get the last id of an item in the database collection and to insert the new item with plus one value
Roi
Yes, my form has 3 stages, and after the first submission I want the ID to be added to the Table so it can be displayed on the second stage. can you possibly give me example code for this?
Hi Daniel,
Before moving on,
Lets say you have 50 items in your collection.
If you decide to erase one of them, you will have duplications.
Will it matter ?
Ok,
In that case you case use Hooks (Before insert)
In the Hook function, query your database collection length:
let numberOfItems;
wixData.query("yourDatabaseCollectionName")
.find()
.then((results) => {
numberOfItems = results.items.length // this represents the number of items in the database collection.
});
Then create “_id” field to “item” object with the numberOfItems plus one.
Good luck!
Roi
Hi Daniel,
Check this out:
import wixData from ‘wix-data’;
export function Jobcard_beforeInsert(item, context) { // item contains the inputFields from the form
return wixData.query("Jobcard")
.limit(1)
.descending('_createdDate') // descending() sorts the results in descending order by property, i choose "_createdDate"
.find()
.then((results) => {
const lastItemInCollection = results.items[0];
item._id = `${Number(lastItemInCollection._id) + 1}`; // "jobcardid" should be "_id". should define the first item as 0 in an empty collection.
return item; // beforeInsert function returns the item
});
}
Hi Roi,
My website is a platform for job search… I had created dynamic profile pages for employers…students will be able to see the job opportunities and can apply too… here comes the problem…I can’t figure out for which particular job a student is applying for…can you help me to fix this?
my website: https://www.fillmypocket.net/
When a student likes a job on he/she applies by clicking on the button" apply" on this page- https://www.fillmypocket.net/Employer-Profile/33443cd2-68d7-4f9f-86be-de303235a31a. This is a unique url with unique ID which was created for employer…after clicking " apply" the student will be directed to this link- https://www.fillmypocket.net/student-application-student-code. This link is a link to application form where student can submit his /her detail.
Now, problem is with - How will I be able to know for which specific job student has applied. I wanted a job profile ID to connect with student application. How can I do that?
Hi,
I want to create case id and mention in the email when user submits the form. I am using automation to trigger a mail when someone submits the form. But how to include unique case id in the response mail. Please help.
My site : https://www.bvc.com.hk/warranty-policy