Hi, I have some questions about doing if/then statements and setting new values based on the results, when working with text.
I query MySQL, get a bunch of data, and then post that data elsewhere.
Simple example:
Twitter: https://twitter.com/twitterdev
Discord: https://discord.com/invite/sample
Instagram: https://www.instagram.com/username
Youtube: https://youtube.com/username
Telegram: https://t.me/username
The data from MySQL comes as a URL (i.e. https://twitter.com/twitterdev).
I want something like:
IF twitter_url contains https, do "Twitter: Twitter: [twitter_url]" ELSE do nothing
IF discord_url contains https, do "Discord: [discord_url]" ELSE do nothing
Or maybe a better way to think of it:
IF twitter_url contains https, set var twitter_publish to "Twitter: [twitter_url]" ELSE do nothing
IF discord_url contains https, set var discord_publish to "Discord: [discord_url]" ELSE do nothing
So for one that only has Instagram and YouTube, the final result would be:
Instagram: https://www.instagram.com/username
Youtube: https://youtube.com/username
I do not want:
Twitter:
Discord:
Instagram: https://www.instagram.com/username
Youtube: https://youtube.com/username
Telegram:
I canât use IF nodes (if URL exists, true) followed by a SET node (set variable âtwitter_lineâ to âTwitter: [twitter_url]â), because there are too many to re-join back with a Merge node, as it only accepts 2 inputs, and I will have a total of 10-15.
Iâve spent a lot of time looking up javascript to do this, but I donât understand how to apply the Javascript to the n8n expressions editor. For example, I found âincludesâ like:
{{$json["twitter_link"].includes(http)}}
But that just returns true or false. I need it to DO something based on the result - output nothing, or output for example, âTwitter: [âtwitter_linkâ]â
With the code editor, I donât understand how to pull in the actual value from a previous node (i.e. [twitter_link] in, and how to make it output a new variable based on the result, like:
var twitter_publish = (twitter_link === "") ? "":"Twitter: [twitter_link]";
Iâm coming from another platform and am really struggling with text manipulation in general with n8n. Without knowing javascript, it seems like Iâm really limited with what I can do with text. There are a ton of things n8n does really well, Iâm not complaining, Iâve just been spinning my wheels all day on this, and other similar text manipulation problems, and Iâm no better off then I was 8 hours ago.
In Integromat/Make, what Iâm trying to do is like:
ifempty(Twitter: twitter_url);"")
Thank you.