How can I write an inbound email action to populate the watch_list field with all TO/CC
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Requirement:
I need to configure ServiceNow so that whenever an email is received:
A case should be created.
The case should be linked to the customer account and populated with customer details.
Any To and CC email addresses should be added to the customer comments watch list.
Field Mapping:
Subject → short_description
Body → description
TO/CC → watch_list
Current Approach:
I am using the following logic in my inbound action script:
Issue:
The target case record is being created successfully, but the watch list is not being updated.
Request for Help:
Could anyone please suggest how to correctly populate the watch list (and possibly work notes list) with To/CC recipients?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
You can use Flow Designer flow and it will be easier to create this with low-code/no-code approach
There is an out of box Flow that can create a case from inbound email. You can map additional field in the action or if action is read-only you can duplicate the action and add 'watch list' mapping as per your requirements from dot-walking email fields. You can use the action in your flow and it should work fine.
If this helped to answer your query, please mark it helpful & accept the solution.
Thanks,
Bhuvan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
did you debug and see?
try this
-> watch list field requires comma separated sysIds
// Step 1: Field mapping
current.short_description = email.subject || "New email case";
current.description = email.body_text || "";
current.contact_type = "email";
// Step 2: Lookup account (assumes acctGR is set earlier)
current.account = acctGR.sys_id;
// Step 3: Lookup contact by From email + Account
var contactGR = new GlideRecord("customer_contact");
contactGR.addQuery("email", (email.from || "").toLowerCase());
contactGR.addQuery("account", acctGR.sys_id);
contactGR.query();
if (contactGR.next()) {
current.contact = contactGR.sys_id;
}
// Step 4: Add To/CC recipients to Watch List and Work Notes List
var allRecipients = [];
if (email.recipients_array && email.recipients_array.length > 0) {
allRecipients = email.recipients_array;
}
var usersToAdd = [];
for (var i = 0; i < allRecipients.length; i++) {
var recEmail = (allRecipients[i] || "").toLowerCase().trim();
if (!recEmail) continue;
var userGR = new GlideRecord("sys_user");
userGR.addQuery("email", recEmail);
userGR.query();
if (userGR.next()) {
usersToAdd.push(userGR.sys_id.toString());
}
}
// Deduplicate and merge with any existing watch_list values
if (usersToAdd.length > 0) {
var currentWatchlist = current.getValue("watch_list") || "";
var watchlistArray = currentWatchlist.split(",").filter(Boolean);
var combined = watchlistArray.concat(usersToAdd);
var uniqueList = [];
var seen = {};
for (var j = 0; j < combined.length; j++) {
if (!seen[combined[j]]) {
uniqueList.push(combined[j]);
seen[combined[j]] = true;
}
}
var sysIdString = uniqueList.join(",");
current.setValue("watch_list", sysIdString); // watch_list expects comma-separated sys_ids[1][2]
current.setValue("work_notes_list", sysIdString); // work_notes_list (if needed)
}
// Step 5: Insert the record
current.insert();
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Hello @shareef_223 ,
As you requested to correctly auto-populate the watch list and also work notes list with TO/CC recipients
Field Mapping:
Subject → short_description
Body → description
TO/CC → watch_list & work_notes_list
Please use the below provided script for Inbound Action Script: