The CreatorCon Call for Content is officially open! Get started here.

Remove Carriage Returns from Email Body

Andrew Bettcher
Kilo Sage

Hi,

As usual, I'm working on inbound actions. We have an email that comes in from a device but it was set to put the alert text on a separate line which means the usual "name:value" set up won't pick it up.

I found this post about how to remove carriage returns from a string and it works in a background script but when I put it in an inbound rule and reprocess an email that fits the trigger, my log shows it as "undefined". Surely the syntax should be then same?? What am I doing wrong?

if (email.subject.indexOf('CKM00130702342/172.20.128.2')>-1){

	email.body = email.body.replace(/\s+/g,'');
	email.body = email.body.replace(/CN=/g,'');
	gs.info('XXBody: ' + email.body);

}

Log:

find_real_file.png

1 ACCEPTED SOLUTION

Shane41
ServiceNow Employee
ServiceNow Employee

Hi Andrew,

email.body is an object and not a string so replace won't work in this case

You will need to use email.body_text to replace the carriages

if (email.subject.indexOf('CKM00130702342/172.20.128.2')>-1){

	email.body_text = email.body_text.replace(/\s+/g,'');
	email.body_text = email.body_text.replace(/CN=/g,'');
	gs.info('XXBody: ' + email.body_text);

}

Hope this helps,

Shane

View solution in original post

4 REPLIES 4

Shane41
ServiceNow Employee
ServiceNow Employee

Hi Andrew,

Can you provide a sample of the email body text & html versions?

Kind Regards,

Shane

find_real_file.png

This is the text in case you need to copy it out:

(CKM00130702342/172.20.128.25) system of which you need to be aware and take action to correct. The alert is:

Port SP A eth11 link down

 

Shane41
ServiceNow Employee
ServiceNow Employee

Hi Andrew,

email.body is an object and not a string so replace won't work in this case

You will need to use email.body_text to replace the carriages

if (email.subject.indexOf('CKM00130702342/172.20.128.2')>-1){

	email.body_text = email.body_text.replace(/\s+/g,'');
	email.body_text = email.body_text.replace(/CN=/g,'');
	gs.info('XXBody: ' + email.body_text);

}

Hope this helps,

Shane

You are a gentleman and a scholar (and an acrobat).

Thank you. Works a treat.