Comment on page
Automatic invoice number
Use this script to automatically assign an invoice number
An invoice number...
- must be unique and should be sequential,
- can consist of numbers and letters,
- is used to uniquely identify an invoice and associate it with the corresponding incoming payment.
Check your country's specific requirements if necessary.
Below are two basic scripts. Both scripts can be used together if needed:
- a table Invoices
- in the Invoices table: a number fieldcalled Invoice number
The easiest way is to store an invoice number right when creating a new invoice (when creating a new record).
Add the following script in the table settings under Trigger on new record:
1
'Invoice no.' := max((select Invoices).'Invoice no.') + 1
%20(EN).png?alt=media&token=f8d56bdb-7442-42fe-b6e4-2c0849c1261f)
Enter the script in the table settings under Trigger on new record
%20EN.png?alt=media&token=70eacb78-c0dd-4835-94ff-f01d7a6bbe6f)
Make sure to save the script in the formula editor
To make the field in which the invoice number is stored non-editable, we recommend setting the field settings of the Invoice No. field under Writable if to
false
..png?alt=media&token=f6525886-f97a-428e-8f79-04f5ceaf9d35)
In the Invoice number field, under Writeable if in the formula editor, enter false to lock the field
To assign a unique invoice number to existing records, the best way is to use a button. With one click, all missing invoice numbers will be added.
- 1.In the table settings, add a button from the layout fields.
- 2.In the button's field settings, copy the script to the On Click field.
- 3.Add the missing numbers by clicking the button.
Done!
🎉
1
let myInvoices := (select Invoices);
2
let maxID := max(myInvoices.'Invoice no.');
3
for invoice in myInvoices do
4
if not invoice.'Invoice no.' then
5
maxID := maxID + 1;
6
invoice.('Invoice no.' := maxID)
7
end
8
end
This script first searches for the largest existing invoice number. The missing numbers are then distributed based on this.
Watch how to subsequently assign a unique invoice number via a button
Want to learn more about invoices? Then we recommend you download our Invoices template and browse through it a bit.
In the Invoices template you will find another script that also ensures unique assignment of invoice numbers.