---
title: "Template JavaScript"
description: "initialize TenXTemplate instances at runtime using JavaScript."
source: "https://github.com/log-10x/modules/tree/main/pipelines/run/units/transform/script/template/unit.yaml"
icon: "material/shape-plus-outline"

---
Defines shared static members accessible by all instances of a [template](https://doc.log10x.com/run/template/ "Import joint JSON schemas files to expand events into well-defined TenXObjects.").

Example: calculating severity from [symbol](https://doc.log10x.com/run/transform/structure/#symbols) values (`Debug`, `Traceback most recent call last`):

```js

export class LevelTemplate extends TenXTemplate {

    constructor() {
    
        // check the template's symbol value starts with any of the configured 'levelTerms' values
        // use the map function to get the level value associated with a matching term
        
        LevelTemplate.level = TenXString.startsWith(
            this.symbolSequence("", "log", 30), 
            TenXMap.fromEntries(TenXEnv.get("levelTerms"))
        );
    }
}
```

## :material-menu: Options

Specify the options below to [configure](/config "configure") multiple Template JavaScript:

|Name|Description|
|---|---|
|[templateClassName](#templateclassname "target inputs of TenXObjects to initialize")|Target inputs of TenXObjects to initialize|
|[templateActions](#templateactions "10x JavaScript template initialization statements to execute")|10x JavaScript template initialization statements to execute|
|[templateActionsFile](#templateactionsfile "Declaring .js file")|Declaring .js file|

### :material-menu-right-outline:**`templateClassName`**

Target inputs of TenXObjects to initialize.

|Type|Required|Names|
|---|---|---|
|String|✔|\[templateClassName, TenXTemplateClassName\]|

Specifies a regex pattern (e.g., `^fluentbit`) a target [input name](https://doc.log10x.com/run/input/stream/#inputname "logical name for the input stream") must match for.


### :material-menu-right-outline:**`templateActions`**

10x JavaScript template initialization statements to execute.

|Type|Default|Names|
|---|---|---|
|List|\[\]|\[templateActions, TenXTemplate\]|

JavaScript statements for initializing target input(s) TenxTemplates.

**NOTE**: This argument is not designed to be set directly, but instead by passing a [.js launch file](https://doc.log10x.com/config/javascript/) containing
these statements nested within an [TenXObject](https://doc.log10x.com/api/js/#TenXObject "Provide structured, reflective access to log/trace events read from input(s).") sub-class constructor as command line argument as described above.


### :material-menu-right-outline:**`templateActionsFile`**

Declaring .js file.

|Type|Default|Names|
|---|---|---|
|String|""|\[templateActionsFile, TenXTemplateFile\]|

Specifies the .js file name declaring [templateActions](https://doc.log10x.com/run/transform/script/template/#templateActions "10x JavaScript template initialization statements to execute").


<br/>:material-github: This unit is defined in [template/unit.yaml](https://github.com/log-10x/modules/tree/main/pipelines/run/units/transform/script/template/unit.yaml "template/unit.yaml"){target="\_blank"}.

