Here is more information. Essentially, if you look at the image below I want to make the row number automatically save into the questionNumber field. As of currently, I have been manually putting in the number, but its way to strenuous and repetitive. PLEASE HELP AS SOON AS POSSIBLE. Thanks for the help!
The row number there is nothing. It’s only presented on the data manager and it’s not part of the database, and if you sort the collection differently all the numbering will be different.
So the answer to your question is no. You can’t use the number of the row.
However, you can set some code to attach running numbers to each new record that when it’s added to your collection.
Could you explain how I would do so?
@jashandeep12120 you should creata a data hook in the data.js file on the backend.
import wixData from 'wix-data';//top of the file
//...
export function MathQuestionBuilder_beforeInsert(item, context) {
return wixData.query("MathQuestionBuilder")
.isNotEmpty("questionNumber")
.descending("questionNumber")
.limit(1)
.distinct("questionNumber")
.then(r => {
if(r.items.length > 0){
item.questionNumber = r.items[0] + 1;
} else {
item.questionNumber = 1;
}
return item;
})
.catch(() => item);
}
[FIXED]