Cannot make notion link in discord node

Hey,

I would like to send into discord link to notion page, link to notion page is contain the page id but without dashes -. In n8n everything looks just fine, but after run node the id is not in the message:

{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        -160,
        160
      ]
    },
    {
      "parameters": {
        "resource": "databasePage",
        "operation": "getAll",
        "databaseId": "e6d56144-06ed-4ac6-9196-a72672264b8f",
        "returnAll": true,
        "options": {
          "filter": {
            "multipleCondition": {
              "condition": {
                "and": [
                  {
                    "key": "isRecurring|select",
                    "condition": "is_not_empty"
                  },
                  {
                    "key": "isProject|checkbox",
                    "condition": "equals",
                    "checkboxValue": true
                  }
                ]
              }
            }
          }
        }
      },
      "name": "Notion",
      "type": "n8n-nodes-base.notion",
      "typeVersion": 1,
      "position": [
        100,
        80
      ],
      "credentials": {
        "notionApi": {
          "id": "1",
          "name": "[email protected]"
        }
      }
    },
    {
      "parameters": {},
      "name": "Merge",
      "type": "n8n-nodes-base.merge",
      "typeVersion": 1,
      "position": [
        620,
        200
      ]
    },
    {
      "parameters": {
        "resource": "databasePage",
        "operation": "getAll",
        "databaseId": "e6d56144-06ed-4ac6-9196-a72672264b8f",
        "returnAll": true,
        "options": {
          "filter": {
            "multipleCondition": {
              "condition": {
                "and": [
                  {
                    "key": "isRecurring|select",
                    "condition": "is_not_empty"
                  },
                  {
                    "key": "date|date",
                    "condition": "is_empty"
                  }
                ]
              }
            }
          }
        }
      },
      "name": "Notion1",
      "type": "n8n-nodes-base.notion",
      "typeVersion": 1,
      "position": [
        100,
        280
      ],
      "credentials": {
        "notionApi": {
          "id": "1",
          "name": "[email protected]"
        }
      }
    },
    {
      "parameters": {
        "webhookUri": "https://discord.com/api/webhooks/921134300471107634/Sxg0lL7rU1yIvRq4OomdkEYTk3TFq-A8SRAHnmPmoko7pdo9JDN74FIrm5Q2LCA-nR7x",
        "text": "=**Error**\nName: {{$json[\"Name\"]}}\nLink: https://www.notion.so/shirobachi/{{$json[\"id\"].replaceAll('-', '')}}\nProblem: {{$json[\"message\"]}}"
      },
      "name": "Discord",
      "type": "n8n-nodes-base.discord",
      "typeVersion": 1,
      "position": [
        980,
        200
      ]
    },
    {
      "parameters": {
        "functionCode": "for (item of items){\n  item.json.message = \"The task cannot be reccuring and project at the same time!\";\n}\n\nreturn items;"
      },
      "name": "Function",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        320,
        80
      ]
    },
    {
      "parameters": {
        "functionCode": "for (item of items)\n  item.json.message = \"The task cannot be reccuring without date!\";\n\nreturn items;"
      },
      "name": "Function1",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        380,
        360
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Notion",
            "type": "main",
            "index": 0
          },
          {
            "node": "Notion1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Notion": {
      "main": [
        [
          {
            "node": "Function",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge": {
      "main": [
        [
          {
            "node": "Discord",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Notion1": {
      "main": [
        [
          {
            "node": "Function1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Function": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Function1": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          }
        ]
      ]
    }
  }
}

What I am doing wrong? :smiley:

Hi @Shirobachi, woah, that’s a funky one, took me quite a while to figure out.

I was first looking at the MDN page for .replaceAll() (from your screenshot) as I had no idea it exists:

And at the very bottom it has a compatibility matrix, suggesting it’s only supported since Node.js 15. The n8n docker image is however built on Node.js 14.

So what has (most likely) happened here is that your browser supports .replaceAll() (which is why you can see it working in the preview), but the server running n8n doesn’t yet. My suggestion would be to use the more traditional .replace() instead which is supported since Node.js 0.10.

To replace all occurrences of -, you can use a regular expression with the g flag. So instead of:
Link: https://www.notion.so/shirobachi/{{$json["id"].replaceAll('-', '')}}

use:
Link: https://www.notion.so/shirobachi/{{$json["id"].replace(/-/g, '')}}

in your Discord node to get the actual values after /shirobachi/:

1 Like

Wow, thanks for that complex explanation! <3

1 Like