- 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 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:05 PM
Hi Ankur,
Thank You for the code. I have used it but its showing single line in email logs as well
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2023 11:14 PM
can you try to write the script in background script and check if new line is getting replaced with <br/>
try this
template.print(grRITMS.getValue('description').replaceAll('\n','<br/>')); // replace new line with <br/> tag
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!