- 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-02-2022 07:34 AM
>> no further dot walking works. you can only get complete email body using email.body.
hmmm yes, this is why im trying to use gr gliderecord.
the email body content includes the email address of the affected user and I'm trying to use that to reference the sysID of the record on the sys_user table, which I want to populate the incident's "client_id" field, with.
- 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!!! 🙂