Describe the problem/error/question
I’m using Javascript expressions to transform data, but I’m getting trailing new-lines after a node in a flow. I’m using this expression:
{{
(
$(‘MySQL’).first().json.assetType === ‘assets’ ? ‘comm_’ :
$(‘MySQL’).first().json.assetType === ‘crypto’ ? ‘crypto_’ :
$(‘MySQL’).first().json.assetType === ‘metals’ ? ‘metals_’ :
$(‘MySQL’).first().json.assetType === ‘currencies’ ? ‘curr_’ :
‘’
) + $(‘Number?2’).first().json.symbol.replace(/[\s\r\n]+/g, ‘’).toUpperCase()
}}
But the output of the node (in this case a PostgreSQL node that wants to update a record), is always ‘symbol\n’. Which results in an error that record (curr_BPX ) is not present in the table. Note the trailing space after the symbol-name (curr_BPX ). No matter the effort, I can’t seem to get rid of it.
What is the error message (if any)?
insert or update on table “PredictionManual” violates foreign key constraint “PredictionManual_assetSymbol_fkey”
Key (assetSymbol)=(crypto_BPX ) is not present in table “Asset”.
(While a check shows that crypto_BPX is in table ‘Asset’.)
Please share your workflow
CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow.)
The workflow is 78000 characters and I can’t share that here. I’ve built many workflows though and all of them are working fine. It’s just that these trailing \n’s start popping up and sanitizing is not working.
Share the output returned by the last node
Last node doesn’t have an output as it’s a response to the webhook.
My expected output is the symbolname in capitals, with a prefix and no trailing whatschamacallit.
Information on your n8n setup
- n8n version:
Latest, 1.69.2
-
Database (default: SQLite):
-
n8n EXECUTIONS_PROCESS setting (default: own, main):
default -
Running n8n via (Docker, npm, n8n cloud, desktop app):
Docker -
Operating system:
Ubuntu 22.04 server