How to get input data from 2 or more previous node?

Hi, I’m new to n8n here.

I know that there is a method this.getInputData() to get input data from previous node, but how can I get data from 2 or more previouse node? for example the workflow below

I have a custom node called RG Info, this node want to consume the same data from Big Query, splitted by Split In Batches node. I’m not sure the MySQL and Slack node will return the data that I want, so, how RG Info get the output data from Big Query using given scenario?

Hi @awk,

In the expression builder at the bottom there is a Nodes option, You can use this to get the results from previous nodes so it would be something like {{$node["Google BigQuery"].parameter["your_field"]}}

1 Like

Hey @awk!

Welcome to the community :sparkling_heart:

To get the output from the SplitInBatches node, you can use the expression {{$node['SplitInBatches'].json['THE COLUMN NAME']}}.

However, you need to use the SplitInBatches node here. n8n will process all the incoming values. You can read more about it here: Looping in n8n | Docs

The expression that @jon shared will return the values of the parameters that you configure in the Google BigQuery node.

ah big thanks @harshil1712

I actually add some code on my custom node

let idx = 0;
while (true) {
	const dataFromSelectedNode = this.getNodeParameter('selector', idx) as string;
	if (dataFromSelectedNode == undefined) {
		break;
	}
	batchData.push({
		"myField": dataFromSelectedNode,
	})
	idx++;
}

works like a charm :tada:

2 Likes