Wix: Data Auto-Value

Hi I would like one of my user input fields to become read-only auto-value from 0001 to 9999.
It is for an invoice system. Any help would be appreciated!

I will try my best here. If you have a field in your data collection for invoicenumbers that are of type Number let’s try the below code to get the next number.

export function getNewInvoiceNumber() {
 return wixData.query("Data Collection Name")
    .then((results => {
      let lastAddedItem = results.items[0];
      let lastInvoiceNumber = lastAddedItem.invoiceNumberField
      let newInvoiceNumber = lastInvoiceNumber++;
      return newInvoiceNumber;

So when you open up the input field set its value to

let newInvoiceNo = await getNewInvoiceNumber();
if (!newInvoiceNo) {newInvoiceNo = 0;}
$w("#numberField").text = newInvoiceNo;

Remember that the field must be of type Number also. Then you can set that to Read Only in the editor.

Also remember that there is not record locking mechanism in Wix so it could happen that you will need to run the function after you have saved the record and just update the invoice number instead or several users might best the same invoice number.

The above code will at least get you going I hope.

@andreas-kviby Hi Andreas, thanks for the response. I am a beginner, I have implemented some code with help before but still very much beginner. So therefore I have a few questions;
Info: dataset = Invoices
field = invoiceNo
First I changed the collection field and input7 from text to number field, and made input 7 ready only.

I implemented the first code: Since my collection field name ends with No instead of Number does that affect the code?

Then, I don’t understand what you want me to do with the second set of codes? What function do I give input7? Since when I click in editor on input7 it asks for minimum and maximum value but that is not what you mean, is it?
Also does code make it a 4or5 digit number like 0001?

@andreas-kviby I am continuing my question here: https://www.wix.com/code/home/forum/community-discussion/wix-data-complete-invoice-system

Thank you!