> 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/global-functions.md).

# Global functions

Create reusable scripts that you can use throughout your app.

Use **Global functions** to write a function once and use it anywhere in your app. A global function stores shared logic that several fields, buttons, or automations need. When you update the function, every place that calls it uses the new logic.

{% hint style="info" %}
**Global functions** belong to one app. They are not shared with other apps.
{% endhint %}

## Create a global function

{% stepper %}
{% step %}

#### Open **Scripting**

Open your app and enable **Builder mode**. In the app navigation, select **Scripting**.
{% endstep %}

{% step %}

#### Add a global function

Select **Add** and choose **Create global function**.
{% endstep %}

{% step %}

#### Name the function

Enter a clear, descriptive name, then select **Create**. Use a descriptive name that explains the result or action. Keep each function focused on one task.

{% hint style="success" %}
If a global function calls another global function, create the called function first.
{% endhint %}
{% endstep %}

{% step %}

#### Write and save the script

Write the reusable script in the editor. Select **Save** when you are done.

{% hint style="info" %}
To create or update a global function with Ninox AI, select the tab with the stars. Simply describe the function you need. Refine it if needed and **Accept**.
{% endhint %}
{% endstep %}
{% endstepper %}

<figure><img src="https://2387596923-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FkPhymvwY495t6ZTxhW8Q%2Fuploads%2FsyQ2MWPGALUL7feRvtOI%2FGlobal%20functions%20screen%20en.png?alt=media&amp;token=4e2b864a-31ca-4b13-9432-a160845b772d" alt=""><figcaption></figcaption></figure>

In the Scripting screen you can:

* Select a function to open it in the editor.
* Use **Search in files** to find a function by name.
* Select **Add** to create another global function.
* Switch between open functions using the tabs.

## Rename or delete a global function

Move the cursor over a function in the **Global functions** list to show **⋮**. Use the menu to rename or delete the function.

## Call a global function

Define a function that returns the value or performs the action you need. Then call it from any other scripts in the app.

{% hint style="warning" %}
Define global functions in dependency order. If one global function calls another, define the called function first.
{% endhint %}

For example, define a function that returns a welcome message:

```ninox
function welcomeMessage() do
    "Welcome to Ninox."
end
```

Call the function by its name, `welcomeMessage()`, where you need it. For example, use it in a logic field or a button to show a message:

```ninox
alert(welcomeMessage())
```


---

# 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/global-functions.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.
