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

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

Hi Ankur,

 

Thank You for the code. I have used it but its showing single line in email logs as well

AnkitaGupte_0-1683612306802.png

 

@Ankita Gupte 

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

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

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!