Make node "json" data available in expression via "json" key

This commit is contained in:
Jan Oberhauser 2020-02-15 16:01:00 -08:00
parent cad86f6623
commit b1719f1bcc
4 changed files with 11 additions and 9 deletions

View file

@ -31,7 +31,7 @@ With the help of expressions, it is possible to set node parameters dynamically
An expression could look like this:
My name is: `{{$node["Webhook"].data["query"]["name"]}}`
My name is: `{{$node["Webhook"].json["query"]["name"]}}`
This one would return "My name is: " and then attach the value that the node with the name "Webhook" outputs and there select the property "query" and its key "name". So if the node would output this data:

View file

@ -75,9 +75,9 @@ Example:
```typescript
// Returns the value of the JSON data property "myNumber" of Node "Set" (first item)
const myNumber = $item(0).$node["Set"].data["myNumber"];
const myNumber = $item(0).$node["Set"].json["myNumber"];
// Like above but data of the 6th item
const myNumber = $item(5).$node["Set"].data["myNumber"];
const myNumber = $item(5).$node["Set"].json["myNumber"];
// Returns the value of the parameter "channel" of Node "Slack".
// If it contains an expression the value will be resolved with the
@ -93,7 +93,7 @@ const channel = $item(9).$node["Slack"].parameter["channel"];
Works exactly like `$item` with the difference that it will always return the data of the first item.
```typescript
const myNumber = $node["Set"].data['myNumber'];
const myNumber = $node["Set"].json['myNumber'];
const channel = $node["Slack"].parameter["channel"];
```

View file

@ -293,7 +293,7 @@ export default mixins(
if (outputData.hasOwnProperty('json')) {
const jsonDataOptions: IVariableSelectorOption[] = [];
for (const propertyName of Object.keys(outputData.json)) {
jsonDataOptions.push.apply(jsonDataOptions, this.jsonDataToFilterOption(outputData.json[propertyName], `$node["${nodeName}"].data`, propertyName, filterText));
jsonDataOptions.push.apply(jsonDataOptions, this.jsonDataToFilterOption(outputData.json[propertyName], `$node["${nodeName}"].json`, propertyName, filterText));
}
if (jsonDataOptions.length) {

View file

@ -127,7 +127,7 @@ export class WorkflowDataProxy {
get(target, name, receiver) {
name = name.toString();
if (['binary', 'data'].includes(name)) {
if (['binary', 'data', 'json'].includes(name)) {
let executionData: INodeExecutionData[];
if (shortSyntax === false) {
// Long syntax got used to return data from node in path
@ -180,7 +180,7 @@ export class WorkflowDataProxy {
throw new Error(`No data found for item-index: "${that.itemIndex}"`);
}
if (name === 'data') {
if (['data', 'json'].includes(name as string)) {
// JSON-Data
return executionData[that.itemIndex].json;
} else if (name === 'binary') {
@ -275,15 +275,17 @@ export class WorkflowDataProxy {
const dataProxy = new WorkflowDataProxy(this.workflow, this.runExecutionData, this.runIndex, itemIndex, this.activeNodeName, this.connectionInputData);
return dataProxy.getDataProxy();
},
$json: {}, // Placeholder
$node: this.nodeGetter(),
$parameter: this.nodeParameterGetter(this.activeNodeName),
$workflow: this.workflowGetter(),
};
return new Proxy(base, {
get(target, name, receiver) {
if (name === '$data') {
if (['$data', '$json'].includes(name as string)) {
// @ts-ignore
return that.nodeDataGetter(that.activeNodeName, true).data;
return that.nodeDataGetter(that.activeNodeName, true).json;
} else if (name === '$binary') {
// @ts-ignore
return that.nodeDataGetter(that.activeNodeName, true).binary;