# Scripts

> Part of the NocoDB documentation (Workflows). Index of all pages: https://nocodb.com/llms.txt. Any docs page is available as Markdown by adding `.md` to its URL.

URL: https://nocodb.com/docs/workflows/scripts
Last updated: 2026-10-03

NocoDB Scripts let you write JavaScript that works with your NocoDB bases, tables and records.

## Overview

NocoDB Scripts is an automation engine. You write JavaScript code that works with your NocoDB bases. Use scripts to automate workflows, do complex operations, transform data and connect to external services. You do all of this in the NocoDB interface.

<Callout type="info">
  Scripts are available from the NocoDB Plus plan on the cloud, and with the Enterprise license in self-hosted environments. On NocoDB Cloud, script runs execute in a managed sandbox and consume 

  [credits](/docs/product/workspaces/credits)

   based on execution time.
</Callout>

## Key Features

* **JavaScript Environment**: Write and run JavaScript code in NocoDB.
* **Database Access**: Query tables and views. Create, update and delete records.
* **User Interaction**: Collect input from users with interactive prompts.
* **External Integration**: Connect to third-party services through HTTP requests.
* **External Package Imports**: Import and use NPM packages from a CDN (for example, lodash and dayjs).
* **Visual Output**: Show results as formatted tables, markdown and more.
* **TypeScript Support**: Get code completion and type checking in the script editor.

## Getting Started

To create your first script:

1. In the left sidebar, click **+ Create New**.
2. Select **Script** from the dropdown menu. You can also select a template to start with a predefined structure.
3. In the pop-up modal, give your script a name and a description. These help you identify its purpose.
4. Write your JavaScript code in the script editor. Use the built-in [API](/docs/workflows/scripts/api-reference) to work with your NocoDB base, tables and records. NocoDB saves your changes automatically.
5. Click the ▶️ button to run your script.

<img alt="Create Script" src={__img0} placeholder="blur" />
<img alt="Create Script" src={__img1} placeholder="blur" />
<img alt="Create Script" src={__img2} placeholder="blur" />

## Script Structure

A typical NocoDB script has this pattern:

```javascript
// 1. Get input from user for interactive scripts
const table = await input.tableAsync('Select a table to analyze:');
const field = await input.fieldAsync('Which field would you like to analyze?', table);

// 2. Perform operations with enhanced query capabilities
const query = await table.selectRecordsAsync({
  fields: [field.name],
  sorts: [{ field: field.name, direction: 'asc' }],
  pageSize: 100
});

// 3. Process records with rich cell value handling
let count = 0;
let totalRecords = query.records.length;

// Handle pagination if there are more records
while (query.hasMoreRecords) {
  await query.loadMoreRecords();
  totalRecords = query.records.length;
}

// Count non-empty values
for (const record of query.records) {
  const value = record.getCellValue(field.name);
  if (value !== null && value !== undefined && value !== '') {
    count++;
  }
}

// 4. Display formatted output with progress
output.markdown(`# Field Analysis Results`);
output.text(`Field: ${field.name} (${field.type})`);
output.text(`Total records analyzed: ${totalRecords}`);
output.text(`Records with values: ${count}`);
output.text(`Empty records: ${totalRecords - count}`);
output.text(`Fill rate: ${((count / totalRecords) * 100).toFixed(1)}%`);

// 5. Show sample values in a table
if (count > 0) {
  const sampleData = query.records
    .filter(record => record.getCellValue(field.name) !== null)
    .slice(0, 5)
    .map(record => ({
      'Record ID': record.id,
      'Value': record.getCellValueAsString(field.name)
    }));
  
  output.markdown('## Sample Values');
  output.table(sampleData);
}
```

## Core Concepts

* **Base Object**: The entry point to your database (`base`).
* **Tables and Views**: Access the structure of your base.
* **Records**: Work with individual data entries.
* **Fields**: Define the structure of your tables.
* **RecordQueryResult**: Handle paginated query results, with advanced loading options.
* **Collaborators**: Work with user data.
* **Session**: Access the current user context and session information.
* **Input**: Collect user input with interactive prompts and file uploads.
* **Output**: Show formatted results as text, markdown, tables and progress indicators.
* **API Integration**: Connect to external services and NocoDB's REST APIs.
* **External Packages**: Import and use NPM packages.

---

## Related pages

- [API Reference](https://nocodb.com/docs/workflows/scripts/api-reference.md): Reference for the objects and methods of the NocoDB Scripts API, for automation and integration.
- [Examples](https://nocodb.com/docs/workflows/scripts/examples.md): Ready-to-use NocoDB script examples that automate tasks and clean up data in your bases.
- [Changelog](https://nocodb.com/docs/workflows/scripts/changelog.md): The changelog lists all changes to the NocoDB Scripts API by release date.
