Skip to content

Commit

Permalink
fix(core): Custom workflow tool tweaks (n8n-io#8561)
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-radency authored Feb 8, 2024
1 parent e28b374 commit ccc0ad5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,9 @@ export class ToolCode implements INodeType {

if (typeof response !== 'string') {
// TODO: Do some more testing. Issues here should actually fail the workflow
executionError = new NodeOperationError(
this.getNode(),
`The code did not return a valid value. Instead of a string did a value of type '${typeof response}' get returned.`,
);
executionError = new NodeOperationError(this.getNode(), 'Wrong output type returned', {
description: `The response property should be a string, but it is an ${typeof response}`,
});
response = `There was an error: "${executionError.message}"`;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export class ToolWorkflow implements INodeType {

{
displayName:
'The workflow will receive "query" as input and the output of the last node will be returned as response',
'This tool will call the workflow you define below, and look in the last node for the response. The workflow needs to start with an Execute Workflow trigger',
name: 'executeNotice',
type: 'notice',
default: '',
Expand All @@ -87,9 +87,9 @@ export class ToolWorkflow implements INodeType {
description: 'Load the workflow from the database by ID',
},
{
name: 'Parameter',
name: 'Define Below',
value: 'parameter',
description: 'Load the workflow from a parameter',
description: 'Pass the JSON code of a workflow',
},
],
default: 'database',
Expand All @@ -111,6 +111,7 @@ export class ToolWorkflow implements INodeType {
default: '',
required: true,
description: 'The workflow to execute',
hint: 'Can be found in the URL of the workflow',
},

// ----------------------------------
Expand All @@ -128,27 +129,30 @@ export class ToolWorkflow implements INodeType {
source: ['parameter'],
},
},
default: '\n\n\n',
default: '\n\n\n\n\n\n\n\n\n',
required: true,
description: 'The workflow JSON code to execute',
},
// ----------------------------------
// For all
// ----------------------------------
{
displayName: 'Response Property Name',
displayName: 'Field to Return',
name: 'responsePropertyName',
type: 'string',
default: 'response',
description: 'The name of the property of the last node that will be returned as response',
required: true,
hint: 'The field in the last-executed node of the workflow that contains the response',
description:
'Where to find the data that this tool should return. n8n will look in the output of the last-executed node of the workflow for a field with this name, and return its value.',
},

// ----------------------------------
// For all
// ----------------------------------
{
displayName: 'Workflow Values',
displayName: 'Extra Workflow Inputs',
name: 'fields',
placeholder: 'Add Value',
type: 'fixedCollection',
description: 'Set the values which should be made available in the workflow',
description:
"These will be output by the 'execute workflow' trigger of the workflow being called",
typeOptions: {
multipleValues: true,
sortable: true,
Expand Down Expand Up @@ -296,6 +300,14 @@ export class ToolWorkflow implements INodeType {
itemIndex,
) as string;

if (!responsePropertyName) {
throw new NodeOperationError(this.getNode(), "Field to return can't be empty", {
itemIndex,
description:
'Enter the name of a field in the last node of the workflow that contains the response to return',
});
}

const workflowInfo: IExecuteWorkflowInfo = {};
if (source === 'database') {
// Read workflow from database
Expand Down Expand Up @@ -399,10 +411,9 @@ export class ToolWorkflow implements INodeType {

if (typeof response !== 'string') {
// TODO: Do some more testing. Issues here should actually fail the workflow
executionError = new NodeOperationError(
this.getNode(),
`The code did not return a valid value. Instead of a string did a value of type '${typeof response}' get returned.`,
);
executionError = new NodeOperationError(this.getNode(), 'Wrong output type returned', {
description: `The response property should be a string, but it is an ${typeof response}`,
});
response = `There was an error: "${executionError.message}"`;
}

Expand Down

0 comments on commit ccc0ad5

Please sign in to comment.