Can I create custom Java scripts in email templates in Sales?
Yes, you can. Consider the following example:
Example: Use a Newline Character in Place of a Comma in an Email Template
In this example, you want to replace commas with newline characters for an Oracle Sales string field that you're using in an email template.
Example string: str = "PRODUCT1, PRODUCT2, PRODUCT3"
The result you're trying to achieve is like this:
- PRODUCT1
- PRODUCT2
- PRODUCT3
You might think that you could simply replace the comma with a newline character
(\n
). However, because the template engine might not support
JavaScript-style .replaceAll()
, try the following approach using a
mustache-style template system.
Use <br>
instead of \n
since HTML doesn't
interpret \n
as a line break:
<div>{{ [$FieldAPIName$].replaceAll(',', '<br>') }}</div>
If replaceAll()
isn't working, try using split()
and join()
:
<div>{{ [$FieldAPIName$].split(',').join('<br>') }}</div>
replaceAll(',', '<br>')
replaces every comma with an HTML line break (<br>
).split(',').join('<br>')
first splits the string by commas and then joins it back with<br>
.