Expressions in Collection Fields Not Evaluating - Need Workaround or Best Practice

Hi n8n community! :waving_hand:

I’m building a custom node and running into a frustrating issue with expressions inside collection fields not being evaluated properly.

The Problem

When I have a collection field like this:

{
  displayName: "Basic Information",
  name: "updateBasicGroup",
  type: "collection",
  options: [
    {
      displayName: "Description",
      name: "description", 
      type: "string",
      default: "",
    }
  ]
}

And users enter expressions like {{ Date.now() }} in the Description field (using fx mode), the expression doesn’t get evaluated. Instead, the literal string "{{ Date.now() }}" gets passed to my routing logic.

What I’ve Tried

  1. Standard routing body: body: { description: "={{$parameter.updateBasicGroup?.description}}" } - expressions stay as literal strings
  2. Complex Object.assign expressions: Still doesn’t evaluate collection field expressions
  3. routing.send approach: send: { type: "body", property: "updateBasicGroup.description" } - this works but only sends one field (I need multiple fields in the request)

Current Workaround

The only solution I found is moving fields out of collections:

// This works - expressions evaluate properly
{
  displayName: "Description",
  name: "description",
  type: "string",
  displayOptions: { show: { operation: ["update"] } }
}

// Routing
routing: {
  request: {
    body: { description: "={{$parameter.description}}" }
  }
}

Questions

  1. Is this a known limitation that expressions in collection fields don’t evaluate?
  2. Are there any workarounds to make expressions work inside collections?
  3. What’s the recommended pattern for custom nodes that need multiple optional fields with expression support?

Moving every field out of collections defeats the purpose of having organized, collapsible field groups and especially for my case, where I also have an update node with lots of parameters, would not really work. Any guidance would be greatly appreciated!

Environment:

  • n8n version: 1.111.0
  • Custom node with TypeScript
  • Using routing configuration

Thanks in advance! :folded_hands:

hello @andya

The expression should be entered in the Expression mode. In fix mode it will be passed as literal string

I think that’s what I did. Here is how it looks:

It even resolves in the UI. Exact same thing works if it’s not in the collection. Am I missing something obvious? :thinking:

Thanks a lot!

That should work. For an example, Convert to File >> to Json has a field called “File Name” that resides inside the collection

n8n/packages/nodes-base/nodes/Files/ConvertToFile/actions/toJson.operation.ts at master · n8n-io/n8n

1 Like

Thanks a lot. I think the difference I see is that my node is a declarative style node while the ConverToFile one is of programmatic style node.

I might go ahead and rewrite my node in programmatic style then, but still would be curious if anyone has this working in declarative style.

I have since rewritten our node in programmatic style. It’s actually cleaner as well for the various things we want to do.

But just if anybody is finding this useful: The problem most likely has to do with declarative style nodes where expressions are evaluated only once.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.