- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-01-2022 03:27 PM
Hi all -- I'm sure its something simple I'm missing here.
I'm writing an inbound email action which will look to "email.body.variableName" for an email address, then check the sys user table for a match where "variableName" matches a user's email address and returns the sysID of the user, so that I can set that as the caller_id on an incident record insert action.
...but the gliderecord script is not working as intended...maybe someone can help please?
Here is what i have:
var emailAddy = email.body.useremail;
emailAddy = emailAddy.toString(); // if I comment out this line, I get different results (it always fails to "else" and sets "Guest" as caller_id)
var grUser = new GlideRecord('sys_user');
grUser.addQuery('email', emailAddy);
grUser.query();
if (grUser.next()) {
current.caller_id = grUser.sys_id;
} else { //else clause may not be needed
current.caller_id = '5136503cc611227c0183e96598c4f706'; //"Guest" sysid -- sets to guest, when not found
}
The problem I'm having is that it always returns the same user, regardless of the email address I put in the body of the email which triggers the incident creation ("useremail:example@domain.com")...the user which is returned is the most recently created user in the system which doesn't have an email address...so my query is wrong somewhere...and it's finding the fist user who doesn't have an email...or no one at all.
...any help is appreciated!!! Thanks in advance everyone! 🙂
Solved! Go to Solution.
- Labels:
-
Incident Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-02-2022 09:48 AM
I think I have this solved, myself and I'm just sharing the solution here for anyone else searching for an answer.
When inbound emails are HTML, the "foo:bar" paring described on https://docs.servicenow.com/bundle/sandiego-servicenow-platform/page/administer/notification/reference/r_SetFieldValsFromTheEmailBody.html/
results in "example@domain.ca<mailto:useremail%3Aexample@domain.ca>" if "foo" is text/reference/string-based and "bar" is an email address.
I suppose sending plaintext explicitly will solve this, but instead I am going to further parse my existing variable that I extracted using the oob method as a failsafe to this.
Hopefully future admins/developers can use this learning experience of mine, for themselves!!! 🙂

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-01-2022 07:05 PM
Hi,
Can you please share what your email body contains when you send an email to ServiceNow.
As per my knowledge this is not correct way to extract information/email address from email body.
var emailAddy = email.body.useremail; // no further dot walking works. you can only get complete email body using email.body.
If you want to extract any information then you need to parse complete email body.
See below links where they have tried to extract information from email body.
Thanks,
Anil Lande
Thanks
Anil Lande

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-01-2022 07:07 PM
Also you can check below links to know how you can parse email body and fetch required attributes.
Thanks,
Anil Lande
Thanks
Anil Lande
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-02-2022 07:29 AM
Hi -- Thanks for the reply, I'll check those links.
with regards to the email content, as of right now I am testing with literally just "useremail:example@domain.com" in the body of the email and trying it to set the client_id of the inc record (as described in OP and what I am trying to do in the script).
FWIW, I am using my company email "james.marshalsay@uleth.ca" as the email address, but have also tested with non email addresses "asdfasdf" (for instance) and valid email addresses that are not in our sys_user table, as well as various other ones (email addresses) that are (in our sys_user table).
I can get it to consistently execute the if statement or fail the if statement (at my will) depending on if I use the "tostring()" method or not...as in, if I don't use tostring, it will just fail always (executing the else statement)...and if I do use tostring, it still "fails" but at least the "if statement returns true", if you know what I'm sayin <hashtag jroc baby>...
....I just can't get it to actually do the lookup appropriately and find the correct user and then set THAT user record as the client_id instead of this other user which doesn't even have an associated email account.
...which is leading me to my suspicion that this has to with me needing to exclude returns where the email account is blank...somehow?...I'm not a strong "code guy", but I try....any help is appreciated.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-02-2022 08:17 AM
...after checking your links, it seems like we are both doing the same thing, except that you are writing additional scripting to manually parse the email address from the body text and I'm attempting to use the *supposed oob function* described here:
https://docs.servicenow.com/bundle/sandiego-servicenow-platform/page/administer/notification/reference/r_SetFieldValsFromTheEmailBody.html
where my "useremail:example@domain.com" is their "foo:bar"
I'd prefer to use this OOB method as described, if possible, rather than a manual parse as you have written on your other solution -- the reason being is that I'm using that method to set other variables on the INC record already, on the inbound action script that I'm currently developing...
...and I'd prefer to not mix/match/cobble methods in the code (lo-code/no-code is teh bezt code amirite?)