Expression execution

Hey everyone,

I’m working on a custom node and attempting to write it in a declarative style. It’s require to compose the body data in the corresponding format before sending it to the api endpoint. I use a method passed in the preSend property. It works correctly when I use fixed values, but expressions come to parameters (this.getNode().parameters) as is, without execution.

In a simple case, value of created_by field in the curly braces with leading = sign:

"additionalFields": {
  "created_by": "={{ 7877026 }}"

I discovered the evaluateExpression method. Is this really the right way to obtain the results of expression executions inside my function?

Would a programmatic style be the better approach for such tasks or should I prepare request body other way, not in preSend?

Any insights or advice from your experiences would be awesome! :slight_smile:

Information on your n8n setup

  • n8n version: 1.16.0
  • Database (default: SQLite): SQLite
  • n8n EXECUTIONS_PROCESS setting (default: own, main): own
  • Running n8n via (Docker, npm, n8n cloud, desktop app): npm
  • Operating system: macos

Hey @chertkov,

Welcome to the community :raised_hands:

You should be able to just do something like the below on your property. Have you already tried this?

routing: {
  send: {
    type: 'body',
    property: 'additionalFields.created_by',

What @Jon said. And if you really want to get a parameter of the current node in the preSend method, you should use this.getNodeParameter('parameterName', 'optiona_fallbackValue').

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