Storing data from multiple sources in a single Sheets row

I am trying to store chat id and form data into a single same sheets row but failing. Used Redis and many other but nothing worked

ht.
If your question hasn’t been asked before, please follow the template below. Skip the questions that are not relevant to you. →

Describe the problem/error/question

What is the error message (if any)?

Please share your workflow

(Select the nodes on your canvas and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow.)

Share the output returned by the last node

Information on your n8n setup

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

Use Merge or Aggregate nodes for combining data, then save directly to Sheet.

I tried them as well but they are not able to merge data because both inputs are not arriving at a time. They come from different executions as they belong to different triggers. So every time the data passes through merge node, there is only one input at a time.

You need to map the exact row from your append row node to the update row node.
Since you are appending the new entry to the sheet and triggering the form right after, if you use “get rows” node in the second flow and extract the last row_number from it and append it to ur data in the code node, this way update row will now work perfectly fine.

Setup form > Structure data > Merge Input 1
Second branch… Setup form > Get rows > limit (get last 1 item) > Merge input 2
(Merge Operation will be: Combine by Position). Update row node after Merge node.

As I am a beginner, Finding little hard to follow your guidance. Could you please download the above json and set it for me? I kindly request you for this. I am stuck at this point since 4 days.

Thank you

Here is the workflow with the added nodes. Make sure you select the Sheets exactly the same in the GetRows node which you are working on. Also, why are you mapping manually instead of automatically? with mapping column being row_number instead of chat_id. 
{
  "nodes": [
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "ec23dcb8-5ed9-4271-8f40-bf81dfa36daa",
              "leftValue": "={{ $json.message?.text }}",
              "rightValue": "/start",
              "operator": {
                "type": "string",
                "operation": "equals",
                "name": "filter.operator.equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        -288,
        16
      ],
      "id": "ba03abf1-22e6-48ec-85fc-1e1e9c93797f",
      "name": "Check for '/start'"
    },
    {
      "parameters": {
        "chatId": "={{ $node[\"Telegram Trigger1\"].json[\"message\"][\"chat\"][\"id\"] }}",
        "text": "=Welcome to Fintrixx! 💐\n\nHere’s what I can do for you:\n\n💰 Live Price Tracker\nGet real-time crypto prices\n\n📊 Assets Analyser\nTrack and understand your holdings\n\n🚨 Price Alerter\nStay notified when markets move\n\nTo get started, please fill out this quick setup form 👇\n\n🔗 https://gopichand4.app.n8n.cloud/form/85ce3cbe-a1a9-4e46-aa39-c949b9f80c8e",
        "additionalFields": {
          "appendAttribution": false
        }
      },
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        0,
        0
      ],
      "id": "dc70f85c-85f5-49e0-aada-f5b79740ee85",
      "name": "Welcome message with form link",
      "webhookId": "1a8cea82-2f78-4655-9216-8c15e8ef2478"
    },
    {
      "parameters": {
        "formTitle": "Setup Fintrixx",
        "formDescription": "Please fill out this one time setup form for daily updates",
        "formFields": {
          "values": [
            {
              "fieldLabel": "Select your currency",
              "fieldType": "dropdown",
              "fieldOptions": {
                "values": [
                  {
                    "option": "Bitcoin (BTC)"
                  },
                  {
                    "option": "Ethereum (ETH)"
                  },
                  {
                    "option": "Tether (USDT)"
                  },
                  {
                    "option": "Binance Coin (BNB)"
                  },
                  {
                    "option": "USD Coin (USDC)"
                  }
                ]
              }
            },
            {
              "fieldLabel": "Enter balance (USD)",
              "fieldType": "number",
              "placeholder": "Eg: 1234.45"
            },
            {
              "fieldLabel": "Enter alert price (USD)",
              "fieldType": "number",
              "placeholder": "Eg: 1234.45"
            }
          ]
        },
        "options": {
          "appendAttribution": false,
          "respondWithOptions": {
            "values": {
              "formSubmittedText": "You can go back to Telgram"
            }
          }
        }
      },
      "type": "n8n-nodes-base.formTrigger",
      "typeVersion": 2.3,
      "position": [
        -560,
        272
      ],
      "id": "cc06ea0f-6433-44cf-997c-a7d06126e4dc",
      "name": "Setup form",
      "webhookId": "85ce3cbe-a1a9-4e46-aa39-c949b9f80c8e"
    },
    {
      "parameters": {
        "jsCode": "const items = $input.all();\n\nreturn items.map(item => {\n  let currency = item.json[\"Select your currency\"];\n  if (currency) {\n    // remove anything inside parentheses, trim spaces, and lowercase\n    currency = currency.replace(/\\s*\\([^)]*\\)/g, '').trim().toLowerCase();\n  }\n\n  return {\n    json: {\n      ...item.json,\n      \"Select your currency\": currency\n    }\n  };\n});\n"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -288,
        272
      ],
      "id": "9b4347d9-d686-4204-ae2b-52ea77e9c444",
      "name": "Structure data"
    },
    {
      "parameters": {
        "operation": "update",
        "documentId": {
          "__rl": true,
          "value": "1DRzAyzNu_JecQ9KRxFGxwNVYrqFlOaT7uoPHn7Cva2I",
          "mode": "list",
          "cachedResultName": "Fintrixx",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1DRzAyzNu_JecQ9KRxFGxwNVYrqFlOaT7uoPHn7Cva2I/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "Master Data",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1DRzAyzNu_JecQ9KRxFGxwNVYrqFlOaT7uoPHn7Cva2I/edit#gid=0"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "Chat id": "={{$json[\"chat_id\"]}}",
            "Currency": "={{ $json[\"Select your currency\"] }}",
            "Balance": "={{ $json[\"Enter balance (USD)\"] }}",
            "Alert price": "={{ $json[\"Enter alert price (USD)\"] }}"
          },
          "matchingColumns": [
            "Chat id"
          ],
          "schema": [
            {
              "id": "Chat id",
              "displayName": "Chat id",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Currency",
              "displayName": "Currency",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Balance",
              "displayName": "Balance",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Alert price",
              "displayName": "Alert price",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        816,
        256
      ],
      "id": "33c1f5d9-9bb9-4623-b576-ee1e59d6b44b",
      "name": "Update row",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "u5oxd2KnDEOZE0jn",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "1DRzAyzNu_JecQ9KRxFGxwNVYrqFlOaT7uoPHn7Cva2I",
          "mode": "list",
          "cachedResultName": "Fintrixx",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1DRzAyzNu_JecQ9KRxFGxwNVYrqFlOaT7uoPHn7Cva2I/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "Master Data",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1DRzAyzNu_JecQ9KRxFGxwNVYrqFlOaT7uoPHn7Cva2I/edit#gid=0"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "Chat id": "={{ $node[\"Telegram Trigger1\"].json[\"message\"][\"chat\"][\"id\"] }}",
            "Currency": "=",
            "Balance": "=",
            "Alert price": "="
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "Chat id",
              "displayName": "Chat id",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Currency",
              "displayName": "Currency",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Balance",
              "displayName": "Balance",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "Alert price",
              "displayName": "Alert price",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        240,
        0
      ],
      "id": "e108e201-0cc8-4398-9edf-671e0b4beff3",
      "name": "Append row",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "u5oxd2KnDEOZE0jn",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "parameters": {
        "updates": [
          "message",
          "callback_query"
        ],
        "additionalFields": {}
      },
      "type": "n8n-nodes-base.telegramTrigger",
      "typeVersion": 1.2,
      "position": [
        -544,
        16
      ],
      "id": "122711a2-c0b6-46c2-8d2e-da3af86d4b89",
      "name": "Telegram Trigger1",
      "webhookId": "401c5ffd-ecac-4700-a808-b86e3c6e9ab1"
    },
    {
      "parameters": {
        "mode": "combine",
        "combineBy": "combineByPosition",
        "options": {}
      },
      "type": "n8n-nodes-base.merge",
      "typeVersion": 3.2,
      "position": [
        624,
        256
      ],
      "id": "0ad474f7-7e0f-4c27-981f-810417147730",
      "name": "Merge"
    },
    {
      "parameters": {
        "documentId": {
          "__rl": true,
          "value": "1t7wHC3cBTmSRE-I5BM0EHwVt6WxLwrFu77KLw4jM-AA",
          "mode": "list",
          "cachedResultName": "Untitled spreadsheet",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1t7wHC3cBTmSRE-I5BM0EHwVt6WxLwrFu77KLw4jM-AA/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "Sheet1",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1t7wHC3cBTmSRE-I5BM0EHwVt6WxLwrFu77KLw4jM-AA/edit#gid=0"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        -96,
        176
      ],
      "id": "1977893b-bcb6-41ff-bd8a-cc4f29484e77",
      "name": "Get row(s) in sheet",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "u5oxd2KnDEOZE0jn",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "parameters": {
        "keep": "lastItems"
      },
      "type": "n8n-nodes-base.limit",
      "typeVersion": 1,
      "position": [
        112,
        176
      ],
      "id": "c000c4da-a6de-4494-a006-4ed288442f72",
      "name": "Limit"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "fcbaa3ce-f6a1-49f0-b7a2-5c06ced52be6",
              "name": "row_number",
              "value": "={{ $json.row_number }}",
              "type": "number"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        336,
        176
      ],
      "id": "5d1504bb-eb55-42c8-88c8-01136c4183e2",
      "name": "Get_Row_Number"
    }
  ],
  "connections": {
    "Check for '/start'": {
      "main": [
        [
          {
            "node": "Welcome message with form link",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Welcome message with form link": {
      "main": [
        [
          {
            "node": "Append row",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Setup form": {
      "main": [
        [
          {
            "node": "Structure data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Structure data": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          },
          {
            "node": "Get row(s) in sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Telegram Trigger1": {
      "main": [
        [
          {
            "node": "Check for '/start'",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge": {
      "main": [
        [
          {
            "node": "Update row",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get row(s) in sheet": {
      "main": [
        [
          {
            "node": "Limit",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Limit": {
      "main": [
        [
          {
            "node": "Get_Row_Number",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get_Row_Number": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "meta": {
    "instanceId": "3341a9f855198254dda764d83711cad9c06c65c3e0a62d6b0de36ddd726e973a"
  }
}
2 Likes

Thanks alot

1 Like

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