How to regenerate random ID?

Hi my dear friends

In my case:
I generate random ID, then I try check if it exist in my database, I regenerate another random one.
The confused thing is that when there is repetitious one, my workflow does not come back to previous nodes to regenerate another one.

Could anyone help me how can I regenerate another id when it was repetitious?

Best regards;

Hey @mooghermez, Something like this should do it.

{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "functionCode": "return [\n  {\n    json: { \n      id: \"asasas\"\n    }\n  }\n]"
      },
      "name": "Function",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        460,
        300
      ]
    },
    {
      "parameters": {
        "conditions": {
          "number": [],
          "boolean": [
            {
              "value1": "={{ (Object.keys($node[\"Sheet\"].json).length === 0) ? false : true }}"
            }
          ]
        }
      },
      "name": "IF",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        870,
        560
      ]
    },
    {
      "parameters": {
        "operation": "lookup",
        "sheetId": "14ZJZBWmOWOFr9NldppEHnACOTReECG3olxG7VgLInHI",
        "lookupColumn": "id",
        "lookupValue": "={{$node[\"Function\"].json[\"id\"]}}",
        "options": {
          "continue": true
        }
      },
      "name": "Sheet",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 1,
      "position": [
        770,
        300
      ],
      "credentials": {
        "googleApi": "asas"
      }
    },
    {
      "parameters": {
        "operation": "append",
        "sheetId": "14ZJZBWmOWOFr9NldppEHnACOTReECG3olxG7VgLInHI",
        "options": {}
      },
      "name": "Google Sheets",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 1,
      "position": [
        1270,
        540
      ],
      "credentials": {
        "googleApi": "asas"
      }
    },
    {
      "parameters": {
        "functionCode": "return [\n  {\n    json: { \n       id: $node['Function'].json.id\n    }\n  }\n]"
      },
      "name": "Function1",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        1070,
        540
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Function",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Function": {
      "main": [
        [
          {
            "node": "Sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF": {
      "main": [
        [
          {
            "node": "Function1",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Function",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Sheet": {
      "main": [
        [
          {
            "node": "IF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Function1": {
      "main": [
        [
          {
            "node": "Google Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}