use inbound email action to add email found in body to watch list
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2024 02:59 PM - edited 02-25-2024 04:16 PM
hi there have a use case where we recive a MS form into ServiceNow
in the body of the email is the email of the person submitting the form ( note the person is not in our user table they are a guest)
\We want to get the grab the email from the body and add them to the watchlist. when the form comes to ServiceNow the field in the email will always come in the the below format.
ReqEmail: bob@bob.com
and we are on Vancouver
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2024 05:55 PM - edited 02-25-2024 06:14 PM
Hi @Fraggle Rock ,
May be try something like this in the actions part:
var wList = current.watch_list;
wList = wList.split(",");
var inputText = String(email.body_text);
// Define the regular expression pattern to match email addresses
var emailPattern = /([a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,})/g;
// Find all matches in the input text
var matches = inputText.match(emailPattern);
// Check if matches were found
if (matches) {
// Loop through matches and add them to the array
for (var i = 0; i < matches.length; i++) {
wList.push(matches[i]);
}
}
current.watch_list = String(wList);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-29-2024 04:04 PM
thanks for that i'll give it a go later.
for my POC i have gone simple with
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-29-2024 04:25 PM - edited 02-29-2024 04:25 PM
Hi @Fraggle Rock ,
// Add All Email Recipients to Watch List
var wList = current.watch_list;
var gList = current.u_group_watch_list;
var rarray = email.recipients_array;
var instanceEmail = gs.getProperty('glide.email.user');
for (var i = 0; i < rarray.length; i++) {
var recipient = rarray[i];
//Check to see if this is a group address...and if so add to the group watch list
var grp = new GlideRecord('sys_user_group');
grp.addQuery('email', recipient);
grp.query();
if (grp.next()) {
if(gList != "") {
gList = (gList + "," + grp.sys_id);
} else {
gList = grp.sys_id;
}
} else {
//It's not a group address...so check to see if it's a user
var gr = new GlideRecord('sys_user');
gr.addQuery('email', recipient);
gr.query();
if (gr.next()) {
// It's a user
if(wList != "") {
wList = (wList + "," + gr.sys_id);
} else {
wList = gr.sys_id;
}
} else {
//It's not a user either...so just add the address to the list...except the instance email address
if (recipient != instanceEmail) {
if(wList != "") {
wList = (wList + "," + recipient);
} else {
wList = recipient;
}
}
}
}
}
current.watch_list = wList;
current.u_group_watch_list = gList;
current.update();
If I could help you with your Query then, please hit the Thumb Icon and mark it as Correct !!
Thanks & Regards,
Sumanth Meda