> For the complete documentation index, see [llms.txt](https://docs.ninox.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.ninox.com/ninox-scripting/automate-your-workflows/explore-core-scripting-elements/logic-editor-features.md).

# Logic editor features

Learn how the Ninox logic editor helps you write, format, search, and troubleshoot scripts faster.

The logic editor helps you write cleaner scripts with less trial and error. It supports you while typing, helps you explore available fields and tables, and adds AI support when you want a faster start.

## **Use the editor sidebar** <a href="#use-the-editor-sidebar" id="use-the-editor-sidebar"></a>

The left side of the editor gives you quick access to three tabs:

* **AI assistant** helps you create or explore script logic.
* **Fields** shows the fields of the current table.
* **Tables** shows tables and their fields.

Use the search box in **Fields** and **Tables** to find names faster.

### **Use the Fields and Tables tabs**

The **Fields** and **Tables** tabs help you insert field names without typing them manually.\
Use **Fields** to work with fields from the current table. Use **Tables** to browse other tables and their fields.\
When you hover over a field, Ninox shows extra details such as the field label and field type.\
When you click a field, Ninox inserts that field into the script immediately. It inserts the field at the current cursor position, or replaces the current selection.

### **Use AI to write or explore scripts** <a href="#use-ai-to-write-or-explore-scripts" id="use-ai-to-write-or-explore-scripts"></a>

The AI assistant can generate Ninox script from a plain-language prompt. Use it when you know the result you want, but not the exact syntax yet.

{% stepper %}
{% step %}

#### **Describe the result**

Open the **AI assistant** tab and describe what the script should do in plain language.
{% endstep %}

{% step %}

#### **Refine the prompt**

Use **Improve message** if you want help making the request more specific before you send it.
{% endstep %}

{% step %}

#### **Review the proposal**

Check the generated script and the short explanation of what it does.
{% endstep %}

{% step %}

#### **Accept or reject the script**

Click **Accept** to keep the proposal, or **Reject** to discard it.
{% endstep %}

{% step %}

#### **Confirm the result**

Click **Confirm** to save the script in the editor.
{% endstep %}
{% endstepper %}

{% hint style="info" %}
Be specific in your prompt. Mention the table, fields, and expected result when possible.
{% endhint %}

### **Use Ninox AI again after saving**

When you reopen a script that was created or edited with AI, the assistant stays available.

You can then use options such as:

* **Explain this code** to get a plain-language summary of the current script
* **Suggest ideas** to explore follow-up changes or next steps

These options help when you want to understand an existing script before you change it.

## **How the editor helps you write logic** <a href="#how-the-editor-helps-you-write-logic" id="how-the-editor-helps-you-write-logic"></a>

These features matter most when you write or edit scripts yourself without the **AI assistant**. If you generate a script with AI, the assistant already handles much of the structure and syntax for you.

The editor still handles several small tasks for you, so you can focus on the logic itself:

* **Line numbers** stay visible by default. They help you scan long scripts and jump to the right place faster.
* **Automatic indentation** keeps related lines grouped clearly. This matters most in `if`, `for`, and other multi-line script structures.
* **Code formatting** gives your script a more consistent layout. Spacing and line breaks become easier to read after saving.
* **Automatic suggestions** suggest matching functions, fields, and other script elements while you type. Press `Enter` to accept the first result, or use the arrow keys to choose another one.
* **Syntax highlighting** helps you distinguish different parts of your script, such as keywords, field names, variables, and text values.
* **Matching parentheses** helps you keep parentheses balanced. When you type `(`, Ninox adds `)` automatically. When your cursor is next to a parenthesis, Ninox highlights the matching one. This makes it easier to see where an expression starts and ends.
* **Comments** help you structure your script, make it more understandable for others or yourself in the future, or save notes about important reasons for the script run order.\
  `//` at the start of a line makes that line a comment. No closing characters are needed.\
  `/* ... */` makes everything between the asterisks a block comment.<br>

  <div data-gb-custom-block data-tag="hint" data-style="warning" class="hint hint-warning"><p>Comments after the last line of a script are not saved.</p></div>
* **Find and replace** is available in the Logic editor. The dialog appears in the upper-right corner when you press `Cmd+F` or `Ctrl+F` on your keyboard while working in the editor.

#### Let's have a look at an example:

{% code lineNumbers="true" %}

```
// Execute the calculation via button 
field_c := field_a * field_b;
/* Show a message 
to confirm the calculation */
alert ("Result successfully stored in field C.")
```

{% endcode %}

If you write comments this way, only lines 2 and 5 will be executed. Keep in mind that no comment after the last line of the script will be saved.

{% hint style="info" %}
If a script looks uneven, save it and reopen it to check the updated formatting.
{% endhint %}

### **What Ninox adjusts automatically**

When you save, Ninox cleans up parts of your logic automatically. This helps you keep scripts consistent and easier to read.

#### **Parentheses**

Ninox removes unnecessary parentheses when they do not change the result of your expression.

```ninox
1 + (2 * 3)
```

This is saved as:

```ninox
1 + 2 * 3
```

The result stays the same because multiplication is evaluated before addition.

#### **Whitespace**

Ninox removes extra spaces and keeps the spacing that improves readability.

```ninox
text ( year ( today ( ) ) )
```

This is saved as:

```ninox
text(year(today()))
```

Ninox may also add spaces around operators or keywords where that makes your logic easier to scan.

#### **Field names after renaming**

You can rename a field without rewriting your existing logic. Ninox keeps the internal field reference, so your script still points to the same field.

#### **Indentation**

Ninox formats indentation automatically when you save. This helps you read nested logic more easily, especially in `if`, `for`, and similar blocks.

## **Save unfinished scripts as drafts** <a href="#save-unfinished-scripts-as-drafts" id="save-unfinished-scripts-as-drafts"></a>

You can save unfinished work as a draft, even when the script contains errors. A draft does not change the live script.

Click **Save draft** to store the current script in this browser. Each user can keep one draft for each script. Saving another draft replaces the previous one.

When you reopen a script with a draft, choose one of these options:

* **Restore draft** loads the saved draft into the editor.
* **Discard draft** opens the live script and deletes the draft.

You can apply a draft only after you fix all errors. Click on **Apply** to update the live script and delete the draft.

### **Keep your work when closing**

If you close the editor with unsaved changes, choose **Keep editing**, **Discard changes**, or **Save draft**.

If errors prevent the script from being applied, Ninox shows the current error count. **Discard changes** removes only your unsaved edits. It does not remove a previously saved draft.

{% hint style="info" %}
Drafts are available only in the browser where you saved them. Ninox deletes your drafts when you log out. If browser storage is unavailable, **Save draft** shows an error.
{% endhint %}

## **Find your place and fix issues faster** <a href="#find-your-place-and-fix-issues-faster" id="find-your-place-and-fix-issues-faster"></a>

The editor also helps you stay oriented and troubleshoot faster.\
Error and warning marks appear while you type. Problem lines are marked in the line number area, and the affected code is underlined. Hover over the red mark at the start of a line to see the message. It is also displayed to the right of the editor in the expandable error panel.

### **Review script errors**

When a script has errors, an error count appears on the right side of the editor. Click on the <i class="fa-square-caret-left">:square-caret-left:</i> icon to expand the error panel.

The panel shows the total number of errors. Each error includes its message and line number, ordered by line. Click a line number to jump to and highlight that line in the editor. You can also copy an individual error, including its line number.

The error count and list update while you type. When all errors are fixed, the error count disappears.

Warnings use a different icon. They do not prevent you from applying the script. If errors prevent you from applying it, the editor shows how many errors you need to fix.

{% hint style="info" %}
A syntax error may not have a line number. In that case, it appears in the error panel without a line link.
{% endhint %}

There is one important detail about errors:

* Syntax errors usually stop the editor from checking the rest of your script. Because of that, you often see only the first syntax issue until you fix it.
* Missing or incorrect references can be marked separately when the rest of your script is still clear enough for the editor to continue checking it.

{% embed url="<https://files.gitbook.com/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FkPhymvwY495t6ZTxhW8Q%2Fuploads%2F19B5AVxTl05Ki6LU5w6Z%2Fen_save%20draft_error%20panel_logic%20editor.mp4?alt=media&token=b744ee3e-2ec0-4721-af37-40f95bdac5bc>" %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
