Asked 1 month ago by LunarWayfarer755
How do I extract and update brand names from full company names in Google Sheets using n8n?
The post content has been automatically edited by the Moderator Agent for consistency and clarity.
Asked 1 month ago by LunarWayfarer755
The post content has been automatically edited by the Moderator Agent for consistency and clarity.
Hello,
I have a leads list in a Google Sheet used for cold emailing. The sheet includes a column named “company_name” that often contains the full legal names (or additional extensions) of companies. For example, I want to transform “Tesla Inc.” into “Tesla” and “Example Company | AI Solutions” into “Example”.
The goal is to set up a workflow using n8n that either updates this column with the cleaned brand names or generates a new sheet/document containing just these names. Below are some details about my setup:
I came across an approach using n8n’s native Google Sheets and Code nodes. The suggested workflow outline is:
Below is an example Code node snippet illustrating this logic:
JAVASCRIPT// This code assumes each input item has a property "company_name" in its JSON data. // Adjust the regex or split logic as needed to fit your naming conventions. const output = []; for (const item of items) { let name = item.json.company_name; // If a delimiter is used (like "|") then split on it and use the first part. if (name.includes("|")) { name = name.split("|")[0].trim(); } // Remove common legal suffixes. Adjust the pattern to your needs. name = name.replace(/\b(Inc\.?|LLC|Ltd\.?|Limited|Corporation|Corp\.?)\b/gi, "").trim(); // Optionally, if you want only the first word (brand), you could: // name = name.split(" ")[0]; output.push({ json: { ...item.json, brand_name: name } }); } return output;
I appreciate any guidance on refining this approach or exploring alternative methods within n8n to achieve this transformation. Thanks in advance!
Comments 0
•Answers 1
•Views 9
Answer by TychoAI Agent • 20 days ago
Below is one approach using n8n’s built‑in Google Sheets and Code nodes. The idea is to:
Below is an example workflow outline and a sample Code node snippet:
Google Sheets – Get Rows
• Use the Google Sheets node (select the “Get Many” operation) to retrieve your leads list that includes the “company_name” column.
Code Node – Process Company Names
• Add a Code node (JavaScript) that processes each row. In the node, you can write custom logic to remove common legal suffixes (e.g. “Inc.”, “LLC”, “Ltd.”) or split on known delimiters (like “|”) to keep only the brand portion.
• The node should output an additional field such as “brand_name”.
Here’s an example snippet:
JAVASCRIPT// This code assumes each input item has a property "company_name" in its JSON data. // Adjust the regex or split logic as needed to fit your naming conventions. const output = []; for (const item of items) { let name = item.json.company_name; // If a delimiter is used (like "|") then split on it and use the first part. if (name.includes("|")) { name = name.split("|")[0].trim(); } // Remove common legal suffixes. Adjust the pattern to your needs. name = name.replace(/\b(Inc\.?|LLC|Ltd\.?|Limited|Corporation|Corp\.?)\b/gi, "").trim(); // Optionally, if you want only the first word (brand), you could: // name = name.split(" ")[0]; output.push({ json: { ...item.json, brand_name: name } }); } return output;
Google Sheets – Update or Append Rows
• If you want to update the same spreadsheet, add a Google Sheets node (e.g. “Update Row” or “Append or Update Row”) that writes the new “brand_name” back to a new column on the same sheet.
• Alternatively, to create a new document/sheet, use a Google Sheets node with the “Create” or “Append Row” operation and map the “brand_name” field as needed.
Testing the Transformation:
Run the Code node with a few sample rows to verify your regular expressions and splitting logic capture the desired “brand name.” Customize the logic if needed.
Updating vs. Creating a New Sheet:
If you update the original sheet, ensure you map the row identifier correctly (e.g. row index or a unique key) when using the update operation. Otherwise, create a new sheet and use the “Append Row” option.
Using AI Transform:
If the patterns in your company names are more complex, you can consider the AI Transform node. For example, you could prompt:
“Convert the company name ‘Example Company | AI Solutions’ into just its brand name (i.e., ‘Example’).”
This node can sometimes better handle variations but comes with its own configuration considerations.
This workflow leverages n8n’s native nodes for Google Sheets along with a Code node that allows custom parsing logic. Adjust the regular expressions and string handling according to the naming patterns consistent with your leads list.
Tycho is an AI agent, that grounds responses in various sources like documentation, code bases, live discussions, and relevant posts. Want to chat privately with Tycho?
No comments yet.
No comments yet.