Hi, I am new in n8n as well as Javascript so I’m a little stuck at this.
I have a Code node that capitalizes the first character of every word. However, it only works for one item instead of multiple ones. I figure I need to change from “Run Once for All Items” to “Run Once for Each Item”.
// Get the Text and store into a variable called myText
const myText = $node["IF (Check Bank)"].json["Email Body"].toLowerCase();
// Now using Regex we can replace every first letter of the Word to Uppercase
const EmailBody = myText.replace(/(^\w|\s\w)/g, m => m.toUpperCase());
// Now return (output) the converted text
return [{
json: { EmailBody }
}]
I’m thinking a Set Node would work for this specific example, with a fancy expression like so, assuming toTitleCase() formats the text like you wanted.
Actually, I think this is the corrected code for your Code Node with “Run Once For Each Item”
// Get the Text and store into a variable called myText
const myText = $node["If (Check Bank)"].json["Email Body"].toLowerCase();
// Now using Regex we can replace every first letter of the Word to Uppercase
const EmailBody = myText.replace(/(^\w|\s\w)/g, m => m.toUpperCase());
// Now return (output) the converted text
return {
json: { "Email Body": EmailBody }
};