Reference a related list in compose email within a record
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2024 12:38 PM
Hey all,
I am trying to pull emails from a related list into the compose email function within a record.
The record is Labor & Employee Relations and the related list is Union Contacts.
The Union Contacts do have an email address associated with it.
As you can see, a branch can have more than one Union Contact associated to it. Only the Union Contact with a branch number that matches the location is shown in the related list. We need the ability to choose who is added to the email. All in the Union Contact associated with the Labor & Employee Relations record should be available to select in the 'to' or 'fields'. I thought the right route would be a script include. Below is the script I have written up and I added it to the Email Client Template but it i cant get it working. is there anything you can see obviously wrong? or is there is another way to do this?
var getUnionContactsEmail = Class.create();
getUnionContactsEmail.prototype = {
initialize: function() {},
build: function() {
var watcher = new GlideRecord("x_abcsm_fact_board_labor_relation_union_contacts");
watcher.addEncodedQuery("sys_idIN" + current.union_contacts.toString());
watcher.query();
var watchlist_email = "";
while (watcher.next()) {
watchlist_email = watchlist_email + watcher.email + ",";
}
watchlist_email = watchlist_email + current.requested_by.email;
var watchlist_str = current.union_contacts.toString();
var watchlist = watchlist_str.split(",");
for (j = 0; j < watchlist.length; j++) {
if (watchlist[j].indexOf("@") > 0) {
watchlist_email = watchlist_email + "," + watchlist[j];
}
}
return watchlist_email;
},
type: 'getUnionContactsEmail'
};
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2024 06:48 PM
Hello Melsarrazin,
I suggest you to do reverse engineering. Please check the field (email), how it is populating and unique identification to get this field. Try applying some filters on the required table and modify your script include accordingly.
Please mark helpful, if my suggestion help you to kick start.
BR,
Suman.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-18-2024 10:47 PM
can you share how are you calling the script include function from email client?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-21-2024 07:12 AM