Add $items to expression and Function-Nodes to get all items

This commit is contained in:
Jan Oberhauser
2020-04-12 18:42:29 +02:00
parent 135e467be9
commit 09e528565f
4 changed files with 114 additions and 50 deletions

View File

@@ -48,11 +48,13 @@ the value would be: "My name is: Jim"
The following special variables are available:
- **$binary**: Incoming binary data of a node
- **$data**: Incoming JSON data of a node
- **$evaluateExpression**: Evaluates a string as expression
- **$env**: Environment variables
- **$node**: Data of other nodes (output-data, parameters)
- **$items**: Environment variables
- **$json**: Incoming JSON data of a node
- **$node**: Data of other nodes (context, output-data, parameters)
- **$parameters**: Parameters of the current node
- **$workflow**: Returns workflow metadata like: active, id, name
Normally it is not needed to write the JavaScript variables manually as they can be simply selected with the help of the Expression Editor.

View File

@@ -59,7 +59,7 @@ return newItems;
```
#### Method: $item(index)
#### Method: $item(index: number)
With `$item` it is possible to access the data of parent nodes. That can be the item data but also
the parameters. It expects as input an index of the item the data should be returned for. This is
@@ -88,6 +88,28 @@ const channel = $item(9).$node["Slack"].parameter["channel"];
```
#### Method: $items(nodeName?: string, outputIndex?: number, runIndex?: number)
Gives access to all the items of current or parent nodes. If no parameters get supplied
it returns all the items of the current node.
If a node-name is given, it returns the items the give node did output. By default of the
first output (index: 0, most nodes only have one output, exceptions are IF and Switch-Node)
and the current run.
Example:
```typescript
// Returns all the items of the current node and current run
const allItems = $items();
// Returns all items the node "IF" outputs (index: 0 which is Output "true" of current run)
const allItems = $items("IF");
// Returns all items the node "IF" outputs (index: 1 which is Output "false" of run 0 which is the first one)
const allItems = $items("IF", 1, 0);
```
#### Variable: $node
Works exactly like `$item` with the difference that it will always return the data of the first item.