0

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:

  1. Assignment of a unique invoice number
  2. Subsequent assignment of a unique invoice number

Requirements

  • a table Invoices
  • in the Invoices table: a Number field called Invoice number

Assign a unique invoice number

The easiest way is to store an invoice number right when creating a new invoice (when creating a new record).

How it works

Add the following script in the table settings under Trigger on new record:

'Invoice no.' := max((select Invoices).'Invoice no.') + 1

To view

Enter the script in the table settings under Trigger on new record

Make sure to save the script in the formula editor

Tip: Lock field

✅ 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.

In the Invoice number field, under Writeable if in the formula editor, enter false to lock the field

Subsequently assign a unique invoice number

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.

How it works

  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.
let myInvoices := (select Invoices);
  let maxID := max(myInvoices.'Invoice no.');
  for invoice in myInvoices do
    if not invoice.'Invoice no.' then
      maxID := maxID + 1;
      invoice.('Invoice no.' := maxID)
    end
  end

This script first searches for the largest existing invoice number. The missing numbers are then distributed based on this.

To view

https://share.ninox.com/1u9tkx1dgybi7jfqrmzlql4g1e68mco2b93c?video

Watch how to subsequently assign a unique invoice number via a button

Our template

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.

Reply

null