Custom declarative node: could not get parameter

Describe the problem/error/question

I am building a custom declarative node with insert and update of an entity. for the update, every property but the id should be optional. Here is an example property:

{
    "displayName": "Description",
    "name": "description",
    "type": "string",
    "displayOptions": {
      "show": {
        "resource": [
          "contact_details"
        ],
        "operation": [
          "update"
        ]
      }
    },
    "required": false,
    "routing": {
      "send": {
        "type": "body",
        "property": "description"
      }
    }
  },

it does not require the input in the UI (which is correct), but when running the node without putting a value into the description field, it throws an error that it cannot get the respective parameter.

My guess is that due to the routing setting n8n somehow tries to get a value anyway. it should just ignore it when its empty.

Setting the default value to an empty string makes the request, but it sends an empty string as value.

What is the error message (if any)?

Could not get parameter “description”!

Information on your n8n setup

  • **n8n version: latest
  • **Database (default: SQLite): sqlite
  • **Running n8n via (Docker, npm, n8n cloud, desktop app): cli
  • **Operating system: macOS

Hey @psteinroe,

If the field is optional you can add it under an additional fields section that way it will only try to add the item if it is selected this is also what we do internally with our nodes so anything that is optional gets moved away.

There is also a presend option so you can write a bit of code to check the value before adding it as well.

hey @Jon

thanks for the quick reply. From a conceptual perspective, why is it possible to have a required: false field then?

Hey @psteinroe,

The quick version is sometimes you may want something on the top level that isn’t required but it would also just be silly to have a required field that can only be set to true :slight_smile:

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