# System and flow control

System and flow control functions help you manage timing, sync, caching, and environment-specific behavior. You can pause a script, inspect raw values, and detect app context.

In this chapter, you will learn how to:

* Control timing in a running script.
* Inspect the current app environment and database status.

<table><thead><tr><th width="233.96484375">Function (A-Z)</th><th>Task</th></tr></thead><tbody><tr><td><code>ninoxApp()</code></td><td>Return the current client or app context</td></tr><tr><td><code>raw()</code></td><td>Return the internal text representation</td></tr><tr><td><code>sleep()</code></td><td>Pause a script briefly</td></tr><tr><td><code>start()</code></td><td>Return the start timestamp of an appointment</td></tr></tbody></table>

## Control timing and execution order

Use these functions when one action should happen only after another has completed.

### Pause a script briefly

Use `sleep()` to force Ninox to wait for a given number of milliseconds before the script continues.

Use it when you want to:

* Add a short delay before a follow-up action.
* Avoid timing issues in a UI flow.
* Wait briefly for another process to settle.
* Show a note or warning before the next step runs.

`sleep(number)`

* `number`: the delay in milliseconds

`sleep()` returns no value.

#### Let’s take a look at some examples:

```ninox
sleep(2000)
```

Pauses the script for 2 seconds.

Tips:

* Keep delays as short as possible.
* Use a delay only when the flow really needs it.

## Inspect raw values and range boundaries

Use these functions when you need the underlying value or the start boundary of a duration or range context.

### Inspect the raw value

Use `raw()` to return the internal raw text representation of a value.

Use it when you want to:

* Convert formatted text into its raw text form.
* Read the internal value behind a color field.
* Reuse formatted content in dialogs or emails.
* Compare the raw form with the displayed form.

`raw(any)`

* `any`: the value you want in raw form

`raw()` returns a string.

#### Let’s take a look at some examples:

```ninox
raw('My sample text')
```

Returns the content of a formatted text value as unformatted text with HTML tags.

```ninox
dialog("Hello", raw('Dialog text'), ["Yes", "No"])
```

Displays a dialog with the contents of the formatted text field `Dialog text`.

```ninox
raw(Color)
```

Returns the internal color value, for example `#EC87E2`.

Tips:

* Use `raw()` when you need the system's internal text representation.
* This is useful for formatted text fields, dialogs, and emails.
* You can format the result again later with `html()`.

## Detect app context and database state

Use these functions when your script should react to the current client or the protection status of the database.

### Detect the current app with `ninoxApp()`

Use `ninoxApp()` to check where your script is executed.

Use it when you want to:

* Adjust behavior by client.
* Diagnose client-specific workflows.

`ninoxApp()`

`ninoxApp()` returns a string that identifies the current environment.

Possible return values include:

* `client`
* `server`

#### Let’s take a look at some examples:

```ninox
ninoxApp() = "client"
```

Returns a string where the script is running.

Tips:

* Use `ninoxApp()` to check if your UI-based functions can be executed, which is not the case if the result is "server".


---

# 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/work-with-functions/system-and-flow-control.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.
