logo

NJP

ServiceNow Learning 106: Problems with indexOf in Inbound Email in ServiceNow

Import · Dec 14, 2023 · article

Hi All,

I have recently found that when "email_body_text" contains "From:" the inbound action will trim the text starting with "From:"

Example:

1. You have a inbound email with below text:

Hi user, Yes, will do. From: IT Service Desk xxx@service-now.com Sent: Friday, May 21, 2021 9:19 AM To: User 1 user1@example.com Subject: Incident INC0207486 -- comments added [cid:image001.png@01D752E5.4BF4C5C0] Short or attachment.

2. Have an inbound action with next lines:

var trimmed = email.body_text.toString();

gs.log('Before = ' + trimmed + ', index = ' + trimmed.indexOf("From:"));

//trimmed = trimmed.substring(0, trimmed.indexOf("From:"));

gs.log('After = ' + trimmed);

3. Process or Reprocess the email

4. The result will be in the system logs Quebec:

2023-05-27 08:22:32 Information Before = Hi user, Yes, will do., index = -1 *** Script

2023-05-27 08:22:32 Information After =

But before Quebec you will see:

2023-05-27 08:22:32 Information Before = Hi user, Yes, will do. From: IT Service Desk xxx@service-now.com Sent: Friday, May 21, 2021 9:19 AM To: User 1 User1@example.com Subject: Incident INC0207486 -- comments added [cid:image001.png@01D752E5.4BF4C5C0] Short or attachment.Rachel.Phillips@enstargroup.com Subject: Incident INC0207486 -- comments added [cid:image001.png@01D752E5.4BF4C5C0] Short or attachment. index = 25

2023-05-27 08:22:32 Information After = Hi user, Yes, will do.

View original source

https://www.servicenow.com/community/developer-blog/servicenow-learning-106-problems-with-indexof-in-inbound-email/ba-p/2762713