All node parameter in a loop

Hello to everyone!
I have a simple question. Is it possibile to get all node properties in a single for loop?

By now I’ve assigned all single properties through the function this.getNodeParameter(prop_name, 0, ‘’), but in this way I need to specify all single properties name. If properties change, I need to change manually also the assignament.

Can I get the properties in a loop similar to: for(let prop of properties) { propList.push([“prop.name”, prop.value])}

Thanks

Welcome, @Diego_Iorio!
this.getNode() returns an object that looks like this:

{
  parameters: {
    resource: 'playlist',
    operation: 'getTracks',
    id: 'spotify:playlist:3w2I1EAz5YLJrQe0CBauxk',
    returnAll: true
  },
  name: 'Spotify',
  type: 'n8n-nodes-base.spotify',
  typeVersion: 1,
  position: [ 764, 289 ],
  credentials: { spotifyOAuth2Api: 'spotify' }
}

If you write code like this:

		console.log(this.getNode());

		const parameters = this.getNode().parameters;

		let pararmeter;
		for(pararmeter in parameters) {
			if(parameters.hasOwnProperty(pararmeter)) {
				console.log(pararmeter);
				console.log(this.getNodeParameter(pararmeter, i));
			}
		}

You will be able to access each parameter name and value.

Let me know if this makes sense!

3 Likes

Hi @erin2722!
It is exactly what I need!
It works fine :slight_smile:

Thank you a lot

1 Like