- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2023 11:49 PM
Hi Experts,
I am working on getting RITM description field values on notification triggering from REQ table.
Below is the code used but I need to get description as it is displaying in RITM description field. However I get everything in single line.
This is RITM Description which is after below another line by line
Below is the preview of notification displaying everything in single line
Below is the code/email script:
(function runMailScript(current, template, email, email_action, event) {
// Add your code here
var grRITMS = new GlideRecord('sc_req_item');
grRITMS.addQuery('request', current.getUniqueValue());
grRITMS.query();
while (grRITMS.next()) {
template.print(grRITMS.getValue('description'));
}
})(current, template, email, email_action, event);
Please help me how will I get it same as displaying RITM Description line after line.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2023 12:38 AM
try this and don't verify in preview.
Check the email in email logs
(function runMailScript(current, template, email, email_action, event) {
// Add your code here
var grRITMS = new GlideRecord('sc_req_item');
grRITMS.addQuery('request', current.getUniqueValue());
grRITMS.query();
while (grRITMS.next()) {
template.print(grRITMS.getValue('description').replaceAll('\r\n','<br/>')); // replace new line with <br/> tag
}
})(current, template, email, email_action, event);
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2023 11:34 PM
Hi Ankur,
I just replaced the line as below and got it
template.print(grRITMS.getValue('description').toString().replaceAll('\n','<br/>'));
Thank alot for the help.
Appreciate it!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2023 01:01 AM
To clarify the issue is that line breaks are written as "\n" in javascript strings.
Emails however are structured as HTML, so they can't format "\n".
In HTML you indicate a line break with "<br>" and you'll have to replace "\n"
You could use "<br/>" as well but it's usually not required in regular HTML in emails.