> ## Documentation Index
> Fetch the complete documentation index at: https://www.nexrender.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Script assets and parameters

> The fields of a script asset, and how to pass values from the job into your script with NX.get

A script asset points to an ExtendScript file and, optionally, passes it values from the job. Your script reads those values with `NX.get`.

## Fields

**type** `string` *required*

Always `script`.

**src** `string` *required*

Where to download the script from: a public `https://` URL or an inline `data:` URL. See [Your first script](https://www.nexrender.com/docs/cloud/scripting/overview.md#your-first-script).

**parameters** `array`

Values your script reads with `NX.get`. Each item has:

* `key` (string, required): the name your script asks for.
* `value` (any JSON value): the value your script gets.
* `type` (string): set to `"function"` to pass code. See [Function parameters](#function-parameters).

**keyword** `string` (default: NX)

The name of the parameters object inside your script. See [Rename the parameters object](#rename-the-parameters-object).

## Read parameters

Define parameters on the asset:

```json Script asset theme={null}
{
  "type": "script",
  "src": "https://example.com/scripts/promo.jsx",
  "parameters": [
    { "key": "headline", "value": "Summer sale" },
    { "key": "discount", "value": 30 },
    { "key": "showBadge", "value": true },
    { "key": "cities", "value": ["Kyiv", "Lisbon", "Kyoto"] },
    { "key": "brand", "value": { "name": "Tekka", "color": [0.63, 0.42, 0.78] } }
  ]
}
```

Then read them by key:

```javascript promo.jsx theme={null}
var headline = NX.get("headline");   // "Summer sale"
var discount = NX.get("discount");   // 30
var showBadge = NX.get("showBadge"); // true
var cities = NX.get("cities");       // ["Kyiv", "Lisbon", "Kyoto"]
var brand = NX.get("brand");         // { name: "Tekka", color: [0.63, 0.42, 0.78] }

nexrender.log(headline + ", " + discount + "% off in " + cities.length + " cities");
```

A value can be any JSON type: string, number, boolean, array, object, or `null`. Nexrender writes each value into the script as JSON, so quotes, line breaks, and non-Latin characters arrive unchanged.

> [!NOTE]
>
> `NX.get` returns `null` for a key the job doesn't define. Give every parameter a fallback, such as `NX.get("headline") || "Default headline"`, so a missing value doesn't break the render.

## Built-in parameters

Every script can read these keys without defining them:

| Key | Value |
| - | - |
| `nxWorkpath` | The absolute path of the job's folder on the render node. Downloaded assets are there, and your script can create files there. |
| `nxUID` | The job's ID. |

```javascript theme={null}
var report = new File(NX.get("nxWorkpath") + "/report.txt");
nexrender.log("Job " + NX.get("nxUID"));
```

## Function parameters

To pass code instead of data, set `"type": "function"` and put the function's source in `value`. `NX.get` then calls the function with the arguments you pass as an array, and returns its result:

```json Script asset theme={null}
{
  "type": "script",
  "src": "https://example.com/scripts/prices.jsx",
  "parameters": [
    {
      "key": "formatPrice",
      "type": "function",
      "value": "function (amount) { return amount.toFixed(2) + ' EUR'; }"
    }
  ]
}
```

```javascript prices.jsx theme={null}
var label = NX.get("formatPrice", [380]);
nexrender.log("Formatted price: " + label); // Formatted price: 380.00 EUR
```

`NX.call("formatPrice", [380])` does the same, and returns `null` when the key isn't a function. Function sources are ExtendScript too. Without `"type": "function"`, a value that looks like a function arrives as a plain string.

## Rename the parameters object

If `NX` clashes with a name your script already uses, pick another name with `keyword`:

```json Script asset theme={null}
{
  "type": "script",
  "src": "https://example.com/scripts/prices.jsx",
  "keyword": "params",
  "parameters": [
    { "key": "currency", "value": "EUR" }
  ]
}
```

```javascript prices.jsx theme={null}
var currency = params.get("currency");
```

## Several scripts in one job

A job can have any number of script assets. They run in the order you list them, each with its own parameters and its own variables. To hand data from one script to the next, write it to a file in the job folder. See [Write a file in the job folder](https://www.nexrender.com/docs/cloud/scripting/examples.md#write-a-file-in-the-job-folder).

## Run the same script in After Effects

While you develop a script, you'll want to run it by hand with **File > Scripts > Run Script File**. Three things only exist when Nexrender runs the script:

* `NX` and `nexrender`.
* `JSON.parse` and `JSON.stringify`. Plain ExtendScript has no `JSON`, so when you run the script by hand, include a JSON implementation such as Douglas Crockford's `json2.js` at the top.
* The array methods `forEach`, `filter`, and `indexOf`. Plain ExtendScript doesn't have them either.

Check for `NX` and `nexrender` first:

```javascript theme={null}
var hasParams = typeof NX !== "undefined";
var headline = (hasParams && NX.get("headline")) || "Preview headline";

function log(message) {
    if (typeof nexrender !== "undefined") {
        nexrender.log(message);
    } else {
        $.writeln(message);
    }
}

log("Headline: " + headline);
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.