Help with Inbound Email Action script

dalewechsler
Mega Expert

We have an Inbound Action set to take information from an incoming email (from a form) that is forwarded into ServiceNow. There is a script in the inbound action that does lots of different things. One of the things it does is searches for a known user based on the origemail address. Once it recognizes the user, it creates the Caller (caller_id) with the known user record. If not a known user, it uses a Guest profile and populates an alternate contact info field (string) and puts the guest user's email address (found in the body of email from form input) in the Watch List.

The form's functioning is about to change, and so will the requirements for this inbound action. With the change, the origemail (From email) will always be the same (an internal email address to avoid spam and other issues). So, now the user will never be recognized, because it isn't the user's email address. So, I'd like the script to look for the email address from the body instead of using origemail. Same with the watch list - instead of populating based on origemail, use the email address from the body.

I've tried lots and lots of different things to make this happen and I can't get it to work.

** Here's the section of the script that searches the sys_user and sets caller:

// - Check to see if this is a Library Services inbound email.
if (email.subject.startsWith("GKR:")||email.subject.startsWith("GIL:")||email.subject.startsWith("DLG:")||email.subject.startsWith("DLGSysadmin")||email.subject.startsWith("NGE:")||email.subject.startsWith("GALILEO:")) {

var target = new GlideRecord('sys_user');
target.addQuery('email', 'CONTAINS', email.origemail);
target.query();

// - If the user Does Not exist
if (!target.hasNext()) {

// - Create the Incident against the Library Guest user
current.caller_id = '4de6da154fd072007c553d728110c7ae';

** Here's the section of the script that populates the watch list:

else{
// Not GALILEO email
// Note: current.opened_by is already set to the first UserID that matches the From: email address
current.caller_id = gs.getUserID();
if (gs.getUserID() == '5136503cc611227c0183e96598c4f706') { //GUEST SYS_ID set watchlist
current.u_customer_watch_list = email.origemail;
}
}

**Here's the body of the email snipped to show where I need to pull the email address for the caller search and to set the watch list:

<SNIP>

Ticket Type: GALILEO
Comment ID: GALILEO:2020-06-12T11:16:00-04:00

Date: 2020-06-12 11:16:00 -0400
First Name: Test User
Email Address: test.user@usg.edu
Phone: 000-000-0000

<SNIP>

**Here is my latest attempt that did not work:

var target = new GlideRecord('sys_user');

target.addQuery('email', 'CONTAINS', email.body_text.EmailAddress); //user record email found in body
target.query();

// - If the user Does Not exist
if (!target.hasNext()) {

// - Create the Incident against the Library Guest user
current.caller_id = '4de6da154fd072007c553d728110c7ae';

I've tried camel case, I've tried email.body.emailAddress, I've tried setting a variable, other things I can't remember. There are other parts of the script that set fields based on the body that work fine. Not sure why I can't set the Caller and customer Watch List with information from the body.

Any advice is greatly appreciated.

Thanks!

7 REPLIES 7

Allen Andreas
Administrator
Administrator

Hi,

You should be able to use something like:

email.body.date - for example.

Spaces are rendered as underscores so for "Email Address", it would be: email.body.email_address

Reference: https://docs.servicenow.com/bundle/orlando-servicenow-platform/page/administer/notification/referenc...

You may need to tighten it to where the value is right next to the colon, like:

Email Address:david@yahoo.com

instead of...

Email Address: david@yahoo.com

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Yeah, I did use an underscore in one of my attempts, but thanks for reminding me of this document. I think the issue is the space in the form to the right of the colon, as you suggest. Another group controls (and is changing the form) so I've asked them to take the space out - so we'll see if that helps. Thanks!

Sounds good.

Keep me posted if that resolves your issue.

If so, be sure to mark the above reply as Correct, if you don't mind.

If not, let us know and we can continue to help investigate!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Hi,

I just wanted to check-in on this and see how things were going.

If my reply above helped guide you correctly, please mark as Correct.

Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!