n8n: Merging a list with a scalar value

As an engineer, I can’t stand repetition. I’m always on the lookout for ways to automate anything that feels even slightly manual. Most of the time, development flows smoothly. But every now and then, something that should be simple throws a wrench in the gears.

This week, I was building a workflow in n8n to process a list of items. Each item had a few fields, let’s call them fieldA, fieldB, and fieldC. Normally, you’d use a loop node to iterate through a list, but in n8n, that’s handled automatically. So a loop node is optional.

The next step in my workflow required each list item to be analyzed against a static set of constants, which we’ll call scalarA and scalarB. No problem, I thought. Just merge them.

Seemed straightforward enough… right?

Nope. Not even close.

I tried the Merge node. Then an Aggregate node. Heck, I even dropped in a code node to manually loop and attach the values in JavaScript. Still no joy. My workspace slowly turned into a spaghetti pile of disconnected nodes, all trying to do the same simple thing: add a constant to every item in a list.

Google wasn’t much help either. Lots of related questions, but no clear solution.

Eventually, I figured out a clean, reliable way to do it and if you’ve ever been stuck on this kind of problem, this post is for you.

The Setup

My list and constants were held in a Google sheet. This way, I can easily update them as needed. This workflow simply reads the list data, then gets the constants.

As a side note, I needed the merge node as a method of synchronization. Sometimes the bottom path didn’t even run yet when the next node tried to process the list, which made for a bunch of fun looking errors!

The Problem

The merge just appends the scalar to the END of the list, adding one additional element to the list. This won’t work.

The Solution

In Merge, use Combine and All Possible Combinations!

The Result

Success!!!!! Now the next node can process each item in the list while still have access to the constant values.

Final Words

This simple merge took waaaaaay longer to figure out than it should have for being so easy. I hope this helps a few people out who were in my situation.

Good Luck, and happy automating!

Stylized letter K inside a microchip symbol, representing Kris' embedded systems brand.

Leave a Reply