Inbound Action Script doesn't work from particular mailbox
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2024 04:57 AM
Hi there,
I have an issue that is driving me crazy and I can't see where the issue might be. Basically, I have a script where an e-mail comes into ServiceNow and, using an Inbound Action, it removes the first e-mail from the e-mail body, checks the e-mail against the User table and, if there is a match, sets it as the Requested For. If not, it will put in a generic one. Here is my script...
// Grabs a list of e-mails from the body text of the e-mail
var pulledEmails = email.body_text.match(/([a-zA-Z0-9._+-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9._-]+)/gi);
var mainUserEmail = pulledEmails[0].toString();
// Checks the User table for the user who has the first of the e-mails listed
// (which will be who needs e-mail released)
var userRec = GlideRecord("sys_user");
userRec.addQuery("user_name", mainUserEmail);
userRec.query();
// If it finds a User record with that e-mail, it will store that info.
// If not, it will put the default user in.
if (userRec.next()) {
var emailUserID = userRec.sys_id.toString();
}
else {
var emailUserID = 'e0847fd2fb1382902b73f783aeefdcca';
This works if I send the e-mail in from several other mailboxes other than the one I need it to come from. It's pulling the e-mail address perfectly from the body text but when it goes to do the Query, it seems to be coming back with nothing as I keep getting my tickets assigned to the default user.
Is there a world where the e-mail text is in a format the Query can't read? I have no idea and I am clutching at straws at this point. Let me know if any of you have any ideas?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2024 09:04 AM
Hi @IDewar
You have to change your query to search with email and also declare emailUserID before your if check
// Grabs a list of e-mails from the body text of the e-mail
var pulledEmails = email.body_text.match(/([a-zA-Z0-9._+-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9._-]+)/gi);
var mainUserEmail = pulledEmails[0].toString();
// Checks the User table for the user who has the first of the e-mails listed
// (which will be who needs e-mail released)
var userRec = GlideRecord("sys_user");
userRec.addQuery("email", mainUserEmail);
userRec.query();
var emailUserID;
// If it finds a User record with that e-mail, it will store that info.
// If not, it will put the default user in.
if (userRec.next()) {
emailUserID= userRec.sys_id.toString();
}
else {
emailUserID = 'e0847fd2fb1382902b73f783aeefdcca';
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2024 09:09 AM
If you want to check all the matched email in user table then you can make below changes in your code
var pulledEmails = body_text.match(/([a-zA-Z0-9._+-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9._-]+)/gi);
var mainUserEmail = pulledEmails;
// Checks the User table for the user who has the first of the e-mails listed
// (which will be who needs e-mail released)
var userRec = GlideRecord("sys_user");
userRec.addQuery("email","IN", mainUserEmail);
userRec.query();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2024 02:31 AM
Hi there,
Sorry for the delay. I had to wait for one of the e-mails to come in and it took a while.
Thank you for making the code a little neater but, sadly, it didn't seem to fix the issue. As I mentioned, the code works perfectly with every other type of e-mail, bar the one I need it to.
Does anyone know if there is a format of e-mail that might break the Inbound Action?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2024 06:18 AM - edited 07-29-2024 06:20 AM
Old code will always go to else block because of wrong query.
Did You keep Logs and verified what value is coming for mainUserEmail field.