Hi, apologies - I know there are tons of questions on the same subject but unfortunately I don’t understand JS and all the answers are specific to the scenario and not helpful with my own. I’m trying to split a string (3 product categories seperated with a /) into 3 individual strings (so an array, I guess?). I have 3 category fields that need to be filled and I can’t do this without splitting the string using JS and the code module.
I’ve tried a bunch of answers to similar questions, trying my best to tweak it to my scenario but to no avail.
Workflow below - it is the ‘Category’ string that needs to be split into 3. For example it will output: “Home Furniture/Garden/Shelving” and I need to seperate these values so I can use them individually.
{
"meta": {
"instanceId": "6cbce4abf5f2183a893e0f13d25668afdcc4d6bf608f7583ff870406cbf58b64"
},
"nodes": [
{
"parameters": {
"rule": {
"interval": [
{
"field": "hours"
}
]
}
},
"id": "a64fd47d-4bf5-42ef-ab32-2caad0c87b10",
"name": "Schedule Trigger",
"type": "n8n-nodes-base.scheduleTrigger",
"typeVersion": 1,
"position": [
-220,
300
]
},
{
"parameters": {
"url": "https://www.songmics.co.uk/songmics-product-2b.csv",
"options": {
"response": {
"response": {
"responseFormat": "file"
}
}
}
},
"id": "cc7f6826-ec68-43e8-b2b2-f269d834304c",
"name": "HTTP Request",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 3,
"position": [
-60,
300
]
},
{
"parameters": {
"options": {}
},
"id": "f71c37ec-0c84-40b0-a45a-c1377b31c7b1",
"name": "Spreadsheet File",
"type": "n8n-nodes-base.spreadsheetFile",
"typeVersion": 1,
"position": [
100,
300
]
},
{
"parameters": {
"values": {
"string": [
{
"name": "SKU",
"value": "={{ $json[\"SKU\"] }}"
},
{
"name": "Name",
"value": "={{ $json[\"Title\"] }}"
},
{
"name": "Categories",
"value": "={{ $json[\"Category\"] }}"
},
{
"name": "Description 1",
"value": "={{ $json[\"Description\"] }}"
},
{
"name": "Description 2",
"value": "={{ $json[\"Description 1\"] }}"
},
{
"name": "Description 3",
"value": "={{ $json[\"Description 2\"] }}"
},
{
"name": "Price",
"value": "={{ $json[\"Price\"] }}"
},
{
"name": "Stock",
"value": "={{ $json[\"Stock\"] }}"
},
{
"name": "Image 1",
"value": "={{ $json[\"image1\"] }}"
},
{
"name": "Image 2",
"value": "={{ $json[\"image2\"] }}"
},
{
"name": "Image 3",
"value": "={{ $json[\"image3\"] }}"
},
{
"name": "Image 4",
"value": "={{ $json[\"image4\"] }}"
},
{
"name": "Image 5",
"value": "={{ $json[\"image5\"] }}"
},
{
"name": "Image 6",
"value": "={{ $json[\"image6\"] }}"
},
{
"name": "Image 7",
"value": "={{ $json[\"image7\"] }}"
},
{
"name": "Image 8",
"value": "={{ $json[\"image8\"] }}"
},
{
"name": "Image 9",
"value": "={{ $json[\"image9\"] }}"
},
{
"name": "Image 10",
"value": "={{ $json[\"image10\"] }}"
},
{
"name": "Image 11",
"value": "={{ $json[\"image11\"] }}"
},
{
"name": "Image 12",
"value": "={{ $json[\"image12\"] }}"
}
]
},
"options": {}
},
"id": "c940e258-0dcc-4a9f-8100-16929a60f35d",
"name": "Set",
"type": "n8n-nodes-base.set",
"typeVersion": 1,
"position": [
260,
300
]
},
{
"parameters": {
"operation": "append",
"application": {
"__rl": true,
"value": "appId1k5e69vV6xS5",
"mode": "id"
},
"table": {
"__rl": true,
"value": "tbl9b6BfJjC8zMzb7",
"mode": "id"
},
"addAllFields": false,
"fields": [
"SKU",
"Title",
"Categories",
"Description 1",
"Description 2",
"Description 3",
"Price",
"Stock",
"Image 1",
"Image 2",
"Image 3",
"Image 4",
"Image 5",
"Image 6",
"Image 7",
"Image 8",
"Image 9",
"Image 10",
"Image 11",
"Image 12"
],
"options": {
"typecast": true
}
},
"id": "ee7ef4b4-955a-4432-a9ad-8a9be93e62aa",
"name": "Airtable1",
"type": "n8n-nodes-base.airtable",
"typeVersion": 1,
"position": [
560,
300
],
"credentials": {
"airtableApi": {
"id": "13",
"name": "Airtable account"
}
}
},
{
"parameters": {
"jsCode": "const categories = [Category 1, Category 2, Category 3];"
},
"id": "361b4e2d-0f97-4db1-9314-c8252808e8a9",
"name": "Code",
"type": "n8n-nodes-base.code",
"typeVersion": 1,
"position": [
400,
300
]
}
],
"connections": {
"Schedule Trigger": {
"main": [
[
{
"node": "HTTP Request",
"type": "main",
"index": 0
}
]
]
},
"HTTP Request": {
"main": [
[
{
"node": "Spreadsheet File",
"type": "main",
"index": 0
}
]
]
},
"Spreadsheet File": {
"main": [
[
{
"node": "Set",
"type": "main",
"index": 0
}
]
]
},
"Set": {
"main": [
[
{
"node": "Code",
"type": "main",
"index": 0
}
]
]
},
"Code": {
"main": [
[
{
"node": "Airtable1",
"type": "main",
"index": 0
}
]
]
}
}
}```
Setup:
Version:0.200.0
Hosted on Cloudron (uses Docker I believe)
On AWS