Your first automations
Set up automations and logic fields to copy data, calculate totals, and generate invoice numbers.
Automate data transfer and calculations
With the data model in place, you can add automations and logic to make the app behave like an invoice system instead of just a static database.
You will:
Use logic fields to calculate line amounts and totals.
Make sure invoices do not change afterward, even if products or customers do.
Why copy data instead of always showing linked data?
In many scenarios, you can simply show data from a linked table via a logic field and always see the latest version. For example, always show the latest product price.
For invoices, this is not what you want:
In most countries, sent invoices must not be changed afterward.
Product names, prices, or VAT rates may change over time.
Invoice records must remain stable as of the time they were issued.
For this reason, you:
Store customer and product data centrally in their tables.
Copy relevant data (name, price, VAT, address) into invoice and invoice item records at creation time via automations.
Use those copied values for calculations and printouts.
Let's take a look at the automations in the “Invoice Management” app.
In automations, you need to refer to fields and tables by their internal names. For example, the field "Product descriptions" has the autogenerated internal name product-descriptions.
Copy product data into invoice items
To ensure invoices stay unchanged even if product data changes later, copy the relevant product information into static fields on the "Invoice items" table.
When a user selects a product in the "Product" reference field, the following should happen:
The product name is copied into "Product description" on the invoice item.
The sales price is copied into "Unit price" on the invoice item.
Set this up as follows:
Open "Invoice items"
Open the "Invoice items" table from the app navigation.
Open the field settings
Click the gear icon in the top right to open the Settings panel. Select the Fields tab. Click the "Products" reference field to open Field settings.

Open the "On update" automation
Navigate to Automations and select On update. The logic editor opens.

Add the script
Add the following script, then click Update to confirm.
The script line by line:
product_descriptionis the target field in the current "Invoice items" table.:=assigns a value to that field.products.product_namereads the field "Product name" from the linked "Products" record.;ends the line. Add it whenever more lines follow.The second line copies the sales price from the linked products record into the "Unit price" field of the current invoice item.
Convert a VAT choice to a numeric value
In the “Products” table, the field “VAT” is a single‑choice field that returns a text value such as “19 %”. For calculations, you need a numeric value, like “19”.
To solve this:
Keep “VAT” as a single-choice in “Products” for a clear UI.
Maintain a numeric field “VAT rate” in “Invoice items”.
Use an automation on the “Product” field in “Invoice items” to:
Read the choice text from
products.'VAT'(for example "19%").Extract the first part:"19" and convert it to a number.
Store it in 'VAT rate'.
Set this up as follows:
Open the field settings
In the "Invoice items" table, open the settings panel and select the Fields tab.
Click the "Products" reference field to open the field settings.
Open the "On update" logic
Navigate to Automations and select On update.
Add the script
Add the following script, then click Update to confirm.
What this does:
First you specify the target field on the current record
vat-rate.Then you use
:=to assign a value.products.text(vat-rate)gets the text displayed by the VAT choice (for example,"19 %").split(..., " ")splits that text at the percent character into parts (["19", "%"]).item(..., 0)selects the first part ("19") while indexing starts at0.number(...)converts the text"19"into the numeric value19.That number is stored in "VAT rate" on the "Invoice items" table, every time you update the "Product" reference field.
You now have a numeric VAT rate ready for calculations.
Calculate line item totals on invoice items
In each invoice item, calculate the net amount and the VAT amount for that line item based on “Quantity” and “Unit price”:
Open "Invoice items"
Navigate to the "Invoice items" table.
Create the "Net amount" logic field
Click the + icon in the table header to add a new field. Enter the Field name "Net amount". Keep the autogenerated internal name. Select the field type Logic.
Add the net amount logic
Switch to the Logic tab. Add the following script, then click Confirm.
This multiplies the unit price by the quantity in the same record.
Create the "VAT amount" logic field
Click Add another field and switch back to the New field tab. Enter the Field name "VAT amount". Keep the autogenerated internal name. Select the field type Logic.
Add the VAT amount logic
Switch to the Logic tab. Add the following script, then click Confirm.
This multiplies quantity, unit price, and VAT rate. It then divides by 100 and rounds to two decimal places. Rounding here helps avoid differences in invoice totals later.
Save the field
Click Add field.
Calculate invoice totals
On the “Invoices” table, you can now calculate the totals for each invoice by summing up all related invoice items.
For each invoice, you want to see:
The net total of all line items
The VAT total of all line items
The gross total (net + VAT)
Set this up as follows:
Open "Invoices"
Navigate to the "Invoices" table.
Create the "Net total" logic field
Create a logic field, for example "Net total".
Add the net total formula
Set the formula to:
This adds up the net amount of all related invoice items for the current invoice.
Create the "VAT total" logic field
Create another logic field named "VAT total".
Add the VAT total formula
Set the formula to:
This adds up the VAT amount of all related invoice items for the current invoice.
Create the "Gross total" logic field
Create one more logic field named "Gross total".
Add the gross total formula
Set the formula to:
This sums the net total and the VAT total to get the final invoice amount.
Here, the sum() function directly uses the “Invoice items” relationship. Ninox automatically accesses all related invoice items records for the current invoice, so you do not need explicit key fields or select statements.
Calculate the expected payment date
In the “Invoices” table, you can calculate an expected payment date based on the creation date of the invoice, and the selected “Payment term”.
Because “Payment term” is a single-choice field, you need to handle all possible options. With many options, a switch case structure is easier to read than multiple nested if ... then ... else statements.
Open "Invoices"
Open the "Invoices" table.
Open the field settings
Click the gear icon to open the Settings panel.
Make sure you are on the Fields tab.
Create the "Expected payment date" logic field
Create a new logic field, for example "Expected payment date".
Add the formula
Set the formula to something like this:
What this does:
switch text(payment_term) dochecks which option is selected in the “Payment term” field.text(payment_term)gives the text value of the chosen option. Withouttext(), you would get the numeric ID of the selected option.
Each
caseblock defines how to calculate the expected date for one option.For fixed time spans such as “1 week” or “30 days”, it adds that many days to “Creation date”.
The
defaultblock defines what should happen if none of the cases match.Here, it falls back to creation date plus 30 days.
You can adapt the case labels and numbers to exactly match your “Payment term” choices.
Generate unique invoice numbers
Every invoice needs a unique invoice number. You can generate it automatically when a new invoice is created, using the On create automation on the “Invoices” table.
In this example, invoice numbers follow the format: "INV-2026-0001" (prefix + year + running number with leading zeros).
Open "Invoices"
Open the "Invoices" table.
Open the table settings
Click the gear icon to open the Settings panel.
Select the tabs Table and Settings.
Open the "On create" automation
Under Automations, choose On create.
Add the script
Add the following script and click Confirm:
What this does:
myYearstores the current year.myRNfinds the highest existing invoice number for this year.It selects all invoices whose creation date is in
myYear.It extracts the numeric part of
invoice_numberstarting at position9, after"INV-YYYY-".number(...)removes the leading zeros and transformes the string to a real number data type.It then takes the maximum of these numbers.
invoice_number := ...composes the new invoice number.It adds the prefix
"INV-".It adds the current year.
It adds a dash.
It adds the incremented running number, formatted to 4 digits with leading zeros using
"0000".
creation_date := today()sets the creation date when the invoice is created.
Generate unique customer numbers (Customers table)
You can use a similar approach to create unique customer numbers in the "Customers" table, for example: "CU-00001".
Open "Customers"
Open the "Customers" table.
Open the table settings
Click the gear icon to open the Settings panel.
Select the tabs Table and Settings.
Open the "On create" automation
Under Automations, choose On create.
Add the script
Add the following script and click Confirm:
What it does:
select customersgets all existing customers.substr(customer_number, 3)takes the customer number without the prefix.For example, from "CU-00001" it extracts "00001".
number(...)converts that text to a number.max(...)returns the highest existing number.myLast + 1increments it for the new record.format(..., "00000")formats the number with five digits and leading zeros.The result is combined with the
"CU-"prefix and written back to "Customer number".
Add example data to your app
If you want to see what your first app looks like with a bit more data, use the Ninox AI assistant to generate sample records for testing.
This prompt assumes you used the same table and field names as in the Your first app guide.
Open a table in Builder mode
Open any table in your app and switch to Builder mode.
In the settings panel, select the tab Form and Add. Scroll down to Controls.

Create a button field
Drag a field of type Button into the form. Name it "Generate sample data".
Open the button automation
Open the button field settings and go to On click.
Ask the AI assistant for the script
In the AI chat paste the prompt below.
Accept the generated script
When the AI assistant inserts the script into the editor, click Accept. Then click Confirm.
Run the button
Exit Builder mode and click your new button.
If your app structure matches this guide, Ninox creates sample records in all four tables.
Last updated
Was this helpful?