mirror of
				https://github.com/n8n-io/n8n-nodes-starter.git
				synced 2025-10-28 14:12:24 -05:00 
			
		
		
		
	🔀 Merge master
This commit is contained in:
		
				commit
				
					
						b4cce8d55c
					
				
			
		
					 4 changed files with 99 additions and 47 deletions
				
			
		|  | @ -1,5 +1,10 @@ | |||
| import { IExecuteFunctions } from 'n8n-core'; | ||||
| import { INodeExecutionData, INodeType, INodeTypeDescription } from 'n8n-workflow'; | ||||
| import { | ||||
| 	INodeExecutionData, | ||||
| 	INodeType, | ||||
| 	INodeTypeDescription, | ||||
| 	NodeOperationError, | ||||
| } from 'n8n-workflow'; | ||||
| 
 | ||||
| export class ExampleNode implements INodeType { | ||||
| 	description: INodeTypeDescription = { | ||||
|  | @ -14,29 +19,56 @@ export class ExampleNode implements INodeType { | |||
| 		inputs: ['main'], | ||||
| 		outputs: ['main'], | ||||
| 		properties: [ | ||||
| 			// Node properties that the user can see and change on the node.
 | ||||
| 			// Node properties which the user gets displayed and
 | ||||
| 			// can change on the node.
 | ||||
| 			{ | ||||
| 				displayName: 'My String', | ||||
| 				name: 'myString', | ||||
| 				type: 'string', | ||||
| 				default: '', | ||||
| 				placeholder: 'Placeholder value', | ||||
| 				description: 'This is a description', | ||||
| 				description: 'The description text', | ||||
| 			}, | ||||
| 		], | ||||
| 	}; | ||||
| 
 | ||||
| 	// The function below is responsible for actually doing whatever this node
 | ||||
| 	// is supposed to do. In this case, we're just appending the `myString` property
 | ||||
| 	// with whatever the user has entered.
 | ||||
| 	// You can make async calls and use `await`.
 | ||||
| 	async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> { | ||||
| 		const items = this.getInputData(); | ||||
| 
 | ||||
| 		// The node iterates over all input items and adds the key "myString" with the
 | ||||
| 		// value the parameter "myString" resolves to. (This could be a different value
 | ||||
| 		// for each item in case it contains an expression.)
 | ||||
| 		for (let itemIndex = 0; itemIndex < items.length; itemIndex++) { | ||||
| 			const myString = this.getNodeParameter('myString', itemIndex, '') as string; | ||||
| 			const item = items[itemIndex]; | ||||
| 		let item: INodeExecutionData; | ||||
| 		let myString: string; | ||||
| 
 | ||||
| 			item.json['myString'] = myString; | ||||
| 		// Iterates over all input items and add the key "myString" with the
 | ||||
| 		// value the parameter "myString" resolves to.
 | ||||
| 		// (This could be a different value for each item in case it contains an expression)
 | ||||
| 		for (let itemIndex = 0; itemIndex < items.length; itemIndex++) { | ||||
| 			try { | ||||
| 				myString = this.getNodeParameter('myString', itemIndex, '') as string; | ||||
| 				item = items[itemIndex]; | ||||
| 
 | ||||
| 				item.json['myString'] = myString; | ||||
| 			} catch (error) { | ||||
| 				// This node should never fail but we want to showcase how
 | ||||
| 				// to handle errors.
 | ||||
| 				if (this.continueOnFail()) { | ||||
| 					items.push({ json: this.getInputData(itemIndex)[0].json, error }); | ||||
| 				} else { | ||||
| 					// Adding `itemIndex` allows other workflows to handle this error
 | ||||
| 					if (error.context) { | ||||
| 						// If the error thrown already contains the context property,
 | ||||
| 						// only append the itemIndex
 | ||||
| 						error.context.itemIndex = itemIndex; | ||||
| 						throw error; | ||||
| 					} | ||||
| 					throw new NodeOperationError(this.getNode(), error, { | ||||
| 						itemIndex, | ||||
| 					}); | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 
 | ||||
| 		return this.prepareOutputData(items); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue