---
title: "Using doo.form.openForm together with onInitScript"
url: "https://help.tabidoo.cloud/en/article/using-dooformopenform-together-with-oninitscript"
language: "en"
last_updated: "2025-12-16T05:36:56.513Z"
---

# Using doo.form.openForm together with onInitScript

When a form is opened using doo.form.openForm, its onInitScript is executed automatically, the same way as if the form was opened manually by the user.

This allows you to combine:

`**doo.form.openForm**` → for programmatically opening the form

`**onInitScript**` → for running additional logic when the form is initialized (e.g. setting default values, hiding fields, conditional behavior)

This approach is useful when you want the form to behave consistently **regardless of where it is opened from**.

* * *

### Example

#### Opening a form using `doo.form.openForm`

```javascript
doo.form.openForm("Contacts", {
    mode: "new"
});
```

This code opens a new record form for the **Contacts** table.

* * *

#### Using `onInitScript` in the form

In the **form settings**, define an `onInitScript`:

```javascript
// This script runs when the form is opened
doo.form.setValue("status", "New");
doo.form.setValue("source", "Opened via script");
```

When the form is opened using `doo.form.openForm`, the `onInitScript` will automatically run and prefill the fields.

* * *

### Notes

`onInitScript` runs **after the form is initialized**, even if the form was opened programmatically.

-   This makes it ideal for:
-   prefilling default values
-   adjusting field visibility
-   applying conditional logic

It helps keep form logic **inside the form**, instead of duplicating it in multiple scripts that open the form.
