Set assignment group based on incoming email address. Inbound Email Action
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2014 05:46 PM
Hi all,
Im trying to set an assignment group based on the email address in the inbound email actions for notification purposes. It simply isn't working and is returning back blank. Before it defaulted to the "service desk" group so I deleted it for testing purposes and now it just returns blank.
if (email.direct.indexOf("company@xyz.com") > -1) {
current.assignment_group.setDisplayValue("IT Service Desk");
}
Any ideas why this is happening? Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2014 06:36 PM
Hi Freddy
There is a really nice neat solution for handling inbound emails which is built by Ben Hollifield. With this solution, you won't need to write a script, and you will be able to configure everything on a GUI-based interface.. I will leave the link below:
Email Routing Made Easy w/ Postmaster
If this won't fit your needs, I'd recommend to use "gs.log()" function to debug your issue.
Kevin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2014 01:21 PM
Thanks for the tool Kevin. How do I set the assignment group in it?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-25-2014 01:52 PM
Freddy,
To set an assignment group you can simply state:
current.assignment_group.setDisplayValue(email.body.assignment_group);
and in the email, the person (or system) sending the email will identify the assignment group as:
assignment_group: Helpdesk
or
assignment_group: [Display value of your assignment group]
Of course, you would want to validate this assignment group through a GlideRecord query to make sure it exists and set a default if no groups are found.
The possible reason why your assignment is not being set now is because the enclosed if statement is probably evaluating to false.
Keep in mind that doing an indexOf() on a string is different than doing an indexOf() on an array object.
- Array: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/indexOf
- String: String.prototype.indexOf() - JavaScript | MDN
Being that the Inbound Email Actions ServiceNow Wiki says that email.direct is a "comma-separated" list (Inbound Email Actions - ServiceNow Wiki), do a gs.log statement to see what kind of type email.direct actually is.
gs.log('Inbound Actions - email.direct Type: ' + typeof email.direct);
My guess is that email.direct is probably an object and not a string, therefore searching for a "string" may not get you the results you'd expect; AKA it will always return false.
If you deleted the "IT Service Desk" portion in your example like this:
current.assignment_group.setDisplayValue();
It will not set to anything because you do not have any value to set it to in the parenthesis.
If you want to hard-code an assignment group (which is most likely not recommended):
current.assignment_group.setDisplayValue('Your Assignment Group');
Where 'Your Assingment Group's is the exact name (case-sensitive) of the assignment group you want to set it to.