How to escape loop

Hey,

I am wondering how to escape loop.

#1
I have workflow what get all notion pages where via getAll:databasePage and for all of them change some propety via update:databasePage the second block return all changed pages and I wanna after that make one time new notion page (no that times as updated pages)

{
  "nodes": [
    {
      "parameters": {
        "triggerTimes": {
          "item": [
            {
              "hour": 4
            }
          ]
        }
      },
      "name": "Cron",
      "type": "n8n-nodes-base.cron",
      "typeVersion": 1,
      "position": [
        -1300,
        350
      ]
    },
    {
      "parameters": {
        "resource": "databasePage",
        "operation": "update",
        "pageId": "={{$json[\"id\"]}}",
        "propertiesUi": {
          "propertyValues": [
            {
              "key": "Date|date",
              "includeTime": false,
              "date": "={{$json[\"Last edited\"]}}",
              "timezone": "Europe/Amsterdam"
            }
          ]
        }
      },
      "name": "Update date in those tasks",
      "type": "n8n-nodes-base.notion",
      "typeVersion": 1,
      "position": [
        -890,
        350
      ],
      "credentials": {
        "notionApi": {
          "id": "1",
          "name": "[email protected]"
        }
      }
    },
    {
      "parameters": {
        "resource": "databasePage",
        "operation": "getAll",
        "databaseId": "e6d56144-06ed-4ac6-9196-a72672264b8f",
        "returnAll": true,
        "options": {
          "filter": {
            "singleCondition": {
              "key": "Date|date",
              "condition": "is_empty"
            }
          }
        }
      },
      "name": "Get all tasks with no date",
      "type": "n8n-nodes-base.notion",
      "typeVersion": 1,
      "position": [
        -1110,
        350
      ],
      "credentials": {
        "notionApi": {
          "id": "1",
          "name": "[email protected]"
        }
      }
    },
    {
      "parameters": {
        "resource": "databasePage",
        "databaseId": "51041012-9664-43f8-8237-b91d26f87ea9",
        "propertiesUi": {
          "propertyValues": [
            {
              "key": "Name|title",
              "title": "Update dates when was empty"
            },
            {
              "key": "Projekt|select",
              "selectValue": "7a7a5343-5989-4eaa-95c8-fc6da7ebed9c"
            }
          ]
        }
      },
      "name": "Push information to logs",
      "type": "n8n-nodes-base.notion",
      "typeVersion": 1,
      "position": [
        -490,
        340
      ],
      "credentials": {
        "notionApi": {
          "id": "1",
          "name": "[email protected]"
        }
      }
    },
    {
      "parameters": {},
      "name": "NoOp",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        -690,
        350
      ]
    }
  ],
  "connections": {
    "Cron": {
      "main": [
        [
          {
            "node": "Get all tasks with no date",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update date in those tasks": {
      "main": [
        [
          {
            "node": "NoOp",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get all tasks with no date": {
      "main": [
        [
          {
            "node": "Update date in those tasks",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "NoOp": {
      "main": [
        [
          {
            "node": "Push information to logs",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

#2 Also I would like to make title of this page from 3rd block some like updated n pages where n is how much page were updated :smiley:

Thanks in advance!

Go to the node setting and turn on Execute Once.

In title field, you can set an expression like this: {{"Updated " + $items("Updated name in some tasks").length + " pages"}}

1 Like

I am not sure why, but in my case it returns error 400 with following description:

Error: Request failed with status code 400
    at createError (/usr/local/lib/node_modules/n8n/node_modules/axios/lib/core/createError.js:16:15)
    at settle (/usr/local/lib/node_modules/n8n/node_modules/axios/lib/core/settle.js:17:12)
    at IncomingMessage.handleStreamEnd (/usr/local/lib/node_modules/n8n/node_modules/axios/lib/adapters/http.js:269:11)
    at IncomingMessage.emit (events.js:327:22)
    at endReadableNT (internal/streams/readable.js:1327:12)
    at processTicksAndRejections (internal/process/task_queues.js:80:21)
{
  "nodes": [
    {
      "parameters": {
        "triggerTimes": {
          "item": [
            {
              "hour": 4
            }
          ]
        }
      },
      "name": "Cron",
      "type": "n8n-nodes-base.cron",
      "typeVersion": 1,
      "position": [
        450,
        130
      ]
    },
    {
      "parameters": {
        "resource": "databasePage",
        "operation": "update",
        "pageId": "={{$json[\"id\"]}}",
        "propertiesUi": {
          "propertyValues": [
            {
              "key": "Date|date",
              "includeTime": false,
              "date": "={{$json[\"Last edited\"]}}",
              "timezone": "Europe/Amsterdam"
            }
          ]
        }
      },
      "name": "Update date in those tasks",
      "type": "n8n-nodes-base.notion",
      "typeVersion": 1,
      "position": [
        860,
        130
      ],
      "credentials": {
        "notionApi": {
          "id": "1",
          "name": "[email protected]"
        }
      }
    },
    {
      "parameters": {
        "resource": "databasePage",
        "operation": "getAll",
        "databaseId": "e6d56144-06ed-4ac6-9196-a72672264b8f",
        "returnAll": true,
        "options": {
          "filter": {
            "singleCondition": {
              "key": "Date|date",
              "condition": "is_empty"
            }
          }
        }
      },
      "name": "Get all tasks with no date",
      "type": "n8n-nodes-base.notion",
      "typeVersion": 1,
      "position": [
        640,
        130
      ],
      "credentials": {
        "notionApi": {
          "id": "1",
          "name": "[email protected]"
        }
      }
    },
    {
      "parameters": {
        "resource": "databasePage",
        "databaseId": "51041012-9664-43f8-8237-b91d26f87ea9",
        "propertiesUi": {
          "propertyValues": [
            {
              "key": "Name|title",
              "title": "={{\"Updated \" + $items(\"Updated name in some tasks\").length + \" pages\"}}"
            },
            {
              "key": "Projekt|select",
              "selectValue": "7a7a5343-5989-4eaa-95c8-fc6da7ebed9c"
            }
          ]
        }
      },
      "name": "Push information to logs",
      "type": "n8n-nodes-base.notion",
      "typeVersion": 1,
      "position": [
        1260,
        120
      ],
      "executeOnce": true,
      "credentials": {
        "notionApi": {
          "id": "1",
          "name": "[email protected]"
        }
      }
    },
    {
      "parameters": {},
      "name": "NoOp",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        1060,
        130
      ]
    }
  ],
  "connections": {
    "Cron": {
      "main": [
        [
          {
            "node": "Get all tasks with no date",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update date in those tasks": {
      "main": [
        [
          {
            "node": "NoOp",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get all tasks with no date": {
      "main": [
        [
          {
            "node": "Update date in those tasks",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "NoOp": {
      "main": [
        [
          {
            "node": "Push information to logs",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Did I something wrong? If I remove the following expression from the node

{{"Updated " + $items("Updated name in some tasks").length + " pages"}}

Everything work except that no show count number ofc.

Thanks in advance!

That is quite weird. It’s working just fine for me.

Check the example below.

{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "functionCode": "return [\n  {\n    json: {\n      age: 1\n    }\n  },\n    {\n    json: {\n      age: 2\n    }\n  }\n]"
      },
      "name": "Updated name in some tasks",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        510,
        300
      ]
    },
    {
      "parameters": {
        "resource": "databasePage",
        "databaseId": "c7f1bbde-9254-49dc-8fd5-646c4ad731aa",
        "propertiesUi": {
          "propertyValues": [
            {
              "key": "Name|title",
              "title": "={{\"Updated \" + $items(\"Updated name in some tasks\").length + \" pages\"}}"
            }
          ]
        }
      },
      "name": "Push information to logs1",
      "type": "n8n-nodes-base.notion",
      "typeVersion": 1,
      "position": [
        1000,
        300
      ],
      "executeOnce": true,
      "credentials": {
        "notionApi": {
          "id": "328",
          "name": "misma 2"
        }
      }
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Updated name in some tasks",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Updated name in some tasks": {
      "main": [
        [
          {
            "node": "Push information to logs1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
1 Like

I don’t know what was the problem, but it works now! Thanks <3

Okay, quick update,

I think I got where is the problem, error 400 return if n8n formula has NOT space between them and beginning of line. It’s about notion’s property type rich_text have a look in free time in this GIF.

Hope it’s helpful, thanks for your help <3

GIF: https://imgur.com/a/gh3pxzn