# Explore core scripting elements

Scripting gets easier once you learn a few small patterns. In Ninox, most scripts read values, make a decision, or update data. Once these basics feel familiar, the deeper scripting chapters get much easier.&#x20;

In Ninox scripting refer to field or table names with the internal name and not the label. \
Internal names are autogenerated and do not contain any spaces or special characters. \
If your field is labeled "First name", the autogenerated internal name is `first_name`. \
If your field or table is labeled containing special characters like `(` or `.` the autogenerated internal name replaces these with underscores. For example, the field label "My.Customers (New)" would have the autogenerated internal name  `my_customers_new`.\
You can change the internal names at any time. Keep in mind to use only lowercase letters (a-z), numbers (0-9), and underscores.

In this guide, you will learn how to:

* work with statements and variables
* choose the right data types
* use operators
* call built-in functions
* control logic with common scripting patterns

{% hint style="info" %}
If you are new to scripting, start with a **Button**. You click it, see the result, and adjust fast.
{% endhint %}

## **Understand statements in Ninox** <a href="#understand-statements-in-ninox" id="understand-statements-in-ninox"></a>

A statement is one instruction. A script is a series of statements.

Common Ninox statements are:

<table><thead><tr><th width="286.2421875">Statement</th><th>What it does</th></tr></thead><tbody><tr><td><code>let</code></td><td>Defines a variable that is populated with a value</td></tr><tr><td><code>if ... then ... else ... end</code></td><td>Makes a decision based on conditions</td></tr><tr><td><code>for ... do ... end</code></td><td>Repeats logic for several records</td></tr><tr><td><code>while ... do ... end</code></td><td>Repeats while a condition stays true</td></tr><tr><td><code>alert()</code></td><td>Shows a message</td></tr><tr><td><code>select()</code></td><td>Finds records</td></tr><tr><td><code>create()</code></td><td>Creates a record</td></tr><tr><td><code>delete()</code></td><td>Deletes one or multiple records</td></tr></tbody></table>

You will also see these patterns often:

* `else if` for more than two outcomes
* `switch ... case` for fixed options
* `select ... where` to filter records
* `order by` to sort records
* `for ... in ... do ... end` to loop through records or list items
* `for ... from ... to ... do ... end` to loop through a numeric range

Try this as your first script:

```ninox
alert("Hello! You clicked the button.")
```

This script opens a message when the button runs.

Why this is a good first example:

* you see the result immediately
* it is easy to test
* it helps you understand where the script output appears

<figure><img src="/files/tAbYhK8N5vMWaWQsFYX1" alt=""><figcaption></figcaption></figure>

## **Work with data types and variables** <a href="#work-with-data-types-and-variables" id="work-with-data-types-and-variables"></a>

Before you write logic, check what kind of value you are working with. A number behaves differently from text, a date, or a record.

{% hint style="info" %}
A field is something you add in **Builder mode**. A data type is the kind of value your script reads, stores, or returns.
{% endhint %}

### **What is a data type in Ninox?** <a href="#what-is-a-data-type-in-ninox" id="what-is-a-data-type-in-ninox"></a>

A data type defines what a value is. Choosing the correct type keeps conditions, calculations, and comparisons reliable.

Common field-to-type mappings are:

* **Text** and **Multi-line text** fields return **Text**
* **Number** fields return **Number**
* **Yes/no** fields return **Yes or No**
* **Date** fields return **Date**
* **Date and time** fields return **Timestamp**
* **Time** fields return **Time**
* **Duration** fields return **Timeinterval**
* **Relationship** fields return **Record(s)**

Some expressions return **Array** or **JSON** values.

Common scripting data types are:

* **Text** for labels, messages, and names
* **Number** for values you calculate with
* **Yes/No** for `true` and `false`
* **Date**, **Time**, and **Datetime** for time-based logic
* **Record** for one linked record
* **Array** for lists of values or records
* **JSON** for structured key-value data
* **File**, **Location**, and **User** for specialized values

### **What is a variable?** <a href="#what-is-a-variable" id="what-is-a-variable"></a>

A variable stores a value for later use. Variables make scripts easier to read, test, and reuse. If you can store one value and reuse it, you already understand the core idea.

{% stepper %}
{% step %}

### Create a variable

```ninox
let total := 100;
```

This stores the number `100` in the variable `total`.
{% endstep %}

{% step %}

### Change the value

```ninox
total := total + 50;
```

This adds `50` to the current value. `total` is now `150`.
{% endstep %}

{% step %}

### Use the value in a condition

```ninox
if total > 100 then "High" else "Low" end
```

This checks the value and returns `"High"` or `"Low"`.
{% endstep %}
{% endstepper %}

## **Use operators to calculate and compare** <a href="#use-operators-to-calculate-and-compare" id="use-operators-to-calculate-and-compare"></a>

Operators tell Ninox what to do with values. They help you calculate, compare, and combine conditions.

### **Arithmetic operators**

Use arithmetic operators for calculations:

* `+` adds values
* `-` subtracts values
* `*` multiplies values
* `/` divides values
* `%` returns the remainder after integer division
* `()` changes the order of calculation

Examples:

* `let sum := 10 + 5;`
* `let difference := 20 - 8;`
* `let product := 4 * 3;`
* `let ratio := 20 / 4;`
* `13 % 5`
* `(1 + 2) * 3`

### **Comparison operators**

Use comparison operators to check values:

* `=` checks whether two values are equal
* `!=` checks whether two values are different
* `>` checks whether one value is greater
* `<` checks whether one value is smaller
* `>=` checks whether one value is greater or equal
* `<=` checks whether one value is smaller or equal
* `like` checks whether text contains a value

Examples:

* `if status = "Open" then alert("Order is open") end`
* `if status != "Closed" then alert("Still active") end`
* `if total > 100 then alert("High value") end`
* `if age < 18 then alert("Young") end`
* `if total >= 30 then "Card" else "Cash" end`
* `if "Hello" like "el" then "Yes" else "No" end`

### **Logical operators**

Use logical operators to combine conditions:

* `and` means both conditions must be true
* `or` means only one condition must be true

Examples:

* `if is_active and age > 18 then alert("Eligible") end`
* `if status = "Open" or status = "Pending" then alert("Order not closed") end`

### **Other operators and syntax you will see often**

You will see these building blocks in many scripts:

* `:=` assigns a value to a field or variable
* `;` ends a statement
* `" "` wraps text values
* `.` accesses a field or value on a record or JSON object

If you are unsure which operator to use, start with this rule:

* use `:=` to store values
* use `+`, `-`, `*`, `/` to calculate
* use `=`, `!=`, `>`, `<`, `>=`, `<=` to compare
* use `.` to access fields (including reference fields) on a record&#x20;

## **Use built-in functions to save time** <a href="#use-built-in-functions-to-save-time" id="use-built-in-functions-to-save-time"></a>

Functions are ready-made statements or scripts. You call them instead of writing everything from scratch. They save time because they solve common tasks for you.

Typical examples are:

* `sum()` to total values
* `date()` to build a date
* `alert()` to show a message

You do not need to memorize them all. Start with a few common ones and build from there.

For a full list, see [Work with functions](/ninox-scripting/automate-your-workflows/work-with-functions.md).

## **What to learn next** <a href="#what-to-learn-next" id="what-to-learn-next"></a>

Once these basics make sense, continue with:

* [Statements](/ninox-scripting/automate-your-workflows/explore-core-scripting-elements/statements.md)
* [Variables](/ninox-scripting/automate-your-workflows/explore-core-scripting-elements/variables.md)
* [Operators](/ninox-scripting/automate-your-workflows/explore-core-scripting-elements/operators.md)
* [Logic editor features](/ninox-scripting/automate-your-workflows/explore-core-scripting-elements/logic-editor-features.md)

{% hint style="success" %}
You do not need to learn everything at once. Start with short scripts, test often, and build confidence one pattern at a time.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.ninox.com/ninox-scripting/automate-your-workflows/explore-core-scripting-elements.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
