Inbound email action issue, seems that conditions aren't working correctly
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2023 04:11 PM
Hello all,
I'm having an issue with a created inbound email action. I'm trying to get an email assigned to the first person replying to a notification that a ticket was assigned to their group.
Below is a screenshot of what I currently have in the "When to run" tab of the form:
In case it's hard to see, my conditions are what isn't working correctly. First off, I'm not even sure my typed in conditions are correct. My goal is to somehow get this inbound action to also check if the ticket being replied to has the same Assignment group currently applied as the replying user, and if the ticket Assigned To field is blank. This condition doesn't fail on incoming emails but that doesn't mean its correct, because of my issue with the drop down menu conditions.
I need this inbound action to check if the email body starts with the following words: take, Take, taking, Taking, assign to me, Assign to me. So I set all the drop downs to have Body Text>is>[keyword I'm using]. The issue is that this will fail even when my email only has one of the keywords being used.
And below is the email that came in that generated this error. As can be seen, the body text is "take".
If I change the conditions to Body text>contains>[keyword] or Body Text>starts with>[keyword] I don't get any errors no matter what words are in the body of the email, and the inbound action processes even though it shouldn't since the body text restrictions weren't actually met.
I would greatly appreciate help on this issue. First, are my written in conditions correct, and if not, what should I be putting in there since Assignment Group and Assigned To are not options on the drop downs for conditions? And second, what am I doing wrong with my conditions I can choose that cause it to fail when I make the body text = keyword, and pass (inbound action reassigns the ticket to the user who replied, regardless of what assignment group they are in) when I use any other operator regarding Body text?
I'm happy to clarify anything else, and looking forward to any assistance that can be given.
Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2023 05:39 PM
Here's a link.
https://developer.servicenow.com/dev.do#!/learn/learning-plans/tokyo/new_to_servicenow/app_store_lea...
Your condition:
should be more like a Server-side script condition. think like a Ui Action condition. Where everything has to be true to work, so like current.assigned_to=="" && current.assignment_group==user.assignment.group ..
There are similar posts in that "" may not work instead put NULL.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-15-2023 01:08 PM
Thank you for your reply!
I'm not sure where to create this script since the only script dialog box seems to be on the Actions tab. Also, truth be told, I don't know how to script very well, so where would I be able to find examples of scripts I can use? ServiceNow has specifically named variables to use for dot walking and I'm not sure where a good place to go is for that kind of dictionary.
Any assistance on why my options from the drop down menus aren't working as well? those are built in and should be catching at the very least my simple condition of email body text starting with those keywords.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-24-2023 03:48 PM
// Get the current user
var currentUser = gs.getUserID();
// Get the current record
var currentRecord = new GlideRecord(current.table_name);
currentRecord.addQuery('sys_id', current.sys_id);
currentRecord.query();
if (currentRecord.next()) {
// Check if Assigned To is empty and Assignment Group is current user
if (!currentRecord.getValue('assigned_to') && currentRecord.getValue('assignment_group') == currentUser.assignment.group) {
// Get the reply email body
var emailBody = current.email.body_text;
// Check if the reply email body starts with "take"
if (emailBody.startsWith("take")) {
// Get the user from the email and assign the record to them
var userFromEmail = emailBody.split(" ")[1];
var userRecord = new GlideRecord('sys_user');
userRecord.addQuery('email', userFromEmail);
userRecord.query();
if (userRecord.next()) {
currentRecord.setValue('assigned_to', userRecord.getValue('sys_id'));
currentRecord.update();
}
}
}
}
This is what I've come up with and I put it in the Script field on the Actions tab, but still I can't get it to do what I want. Any reply to the notification will assign the ticket to whoever replied, and it assigns a ticket even if the user who replied isn't in that assignment group (this would be to stop anyone on watchlists from assigning the ticket to themselves). Where is my code incorrect?