Execute Javascript code
Task in alpha phase
This Data Factory task is in phase. You can contact the Product-Live team at contact@product-live.com if you want more details and get an early access.
This task allows to execute Javascript code to produce a result based on the given input parameters.
Task name:
Max execution time (secondes):
Examples
json
{
"name": "code-execute-javascript",
"taskReferenceName": "get_input",
"description": "Initialize job inputs",
"inputParameters": {
"data": {
"number": 3
},
"expression": "function f() { return $.data.number % 2 === 0; } f();"
},
"type": "SUB_WORKFLOW",
"startDelay": 0,
"optional": false
}1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
json
{
"name": "code-execute-javascript",
"taskReferenceName": "compute_and_export",
"description": "Compute result and export as file",
"inputParameters": {
"expression": "return { sum: $.data.a + $.data.b };",
"data": { "a": 10, "b": 20 },
"response": "FILE"
},
"type": "SUB_WORKFLOW",
"startDelay": 0,
"optional": false
}1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
json
{
"name": "code-execute-javascript",
"taskReferenceName": "process_files",
"description": "Load and process external files",
"inputParameters": {
"expression": "return { firstItem: $.resources[0].content.items[0] };",
"resources": [
{
"key": "config",
"file": {
"url": "https://..."
},
"loadAs": "JSON"
}
]
},
"type": "SUB_WORKFLOW",
"startDelay": 0,
"optional": false
}1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
json
{
"name": "code-execute-javascript",
"taskReferenceName": "run_script_from_file",
"description": "Load script from a file reference",
"inputParameters": {
"expressionFile": {
"url": "https://...",
"hash": "...",
"name": "script.js"
},
"data": { "value": 42 }
},
"type": "SUB_WORKFLOW",
"startDelay": 0,
"optional": false
}1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
| Property | Type | Required | Description |
|---|---|---|---|
| The name (or type) of the task | |||
| The unique name of the task in your job. It is used to reference this task in the workflow. | |||
| The functional description of this task in your job. | |||
The type of the task. It must be SUB_WORKFLOW. | |||
| : | true: the job continues if there is an error on this task. false: the job fails. | ||
| Input parameters of the task. See below |
Inputs Parameters
WARNING
This task does not support the Data Factory variable as an input parameter.
| Property | Type | Required | Description |
|---|---|---|---|
| The Javascript code to be executed inline. Either or must be provided. The code has access to (input data) and (loaded files) | |||
| File reference containing the Javascript code to execute. Either or must be provided. File must have property | |||
| The data to be used by the Javascript code (accessible via ) | |||
| Array of files to load. Each resource must have: (identifier), (file URL), (TEXT/JSON/XML, default TEXT), (default utf-8). Loaded resources are accessible via as an array with and properties | |||
| (default) or . When , the result is written to a file and contains the file reference | |||
The file output name. (ex: file.txt) |
Outputs
| Property | Type | Description |
|---|---|---|
| The result of the Javascript code execution. When is (default), contains the returned value. When is , contains a file reference with , , and | ||
| File reference containing execution logs (calls to function in the script) |
Script context
The Javascript code has access to:
- - Input data object
- - Array of loaded resources (each with and )
- - Function to log messages (available in logs output)
Example with resources:
javascript
// Access input data
const total = $.data.items.reduce((sum, item) => sum + item.price, 0);
// Access loaded files
const config = $.resources.find(r => r.key === 'config');
log('Config loaded:', config.content);
// Return result
return { total, settings: config.content };1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9