Get RITM description on Req notification

Ankita Gupte
Kilo Sage

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

AnkitaGupte_0-1683528382573.png

Below is the preview of notification displaying everything in single line 

AnkitaGupte_1-1683528516523.png

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.

 

2 ACCEPTED SOLUTIONS

Ankur Bawiskar
Tera Patron
Tera Patron

@Ankita Gupte 

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);

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

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!

View solution in original post

5 REPLIES 5

Weird
Mega Sage

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.