- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2024 10:35 AM
I have been asked to write a script, which will be schedule to run periodically. The script will search for all active contacts associated with a specific customer account, where the "location" field is blank. Ultimately, that list needs to be e-mailed to an external e-mail address.
I have created a script, job, event registration, and notification. When I execute the job, I can see that it runs because I have it sending gs.info() messages but I do not see any e-mail in the outbox (I am running this in Dev right now).
What am I missing? Here is what I have so far (please note that the message in "What will it contain" is not final):
Script:
// Select a random number and use it to track the sequence of log messages in this script.
var seq = Math.floor(Math.random() * 999999) + 1;
gs.info('[{0}]GetContacts: Beginning "User list - no location" scheduled job.', seq++);
// #region Initialize variables
var account = 'bb8083d14755f910291fe0e8036d43ea'
var userList = [];
// #endregion Initialize variables
// #region Get contacts
gs.info('[{0}]GetContacts: Query for contacts contacts at {1}.', seq++, account);
var grContact = new GlideRecord('customer_contact');
grContact.addEncodedQuery('account=' + account + '^user_nameISNOTEMPTY^locationISEMPTY^active=true');
grContact.query();
while (grContact.next()) {
//gs.info('[{0}]GetContacts: Adding {1} to the list.', seq++, grContact.getValue('user_name'));
userList.push(grContact.getValue('user_name'));
}
gs.info('[{0}]GetContacts: There are {1} contacts.', seq++, userList.length);
// #endregion Get contacts
// #region Trigger event
gs.eventQueue('send.genericemail', null, 'testuser@domain.com', userList.length);
// #endregion Trigger event
Event registration:
Notification:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2024 07:31 AM
Turns out that the notification was in a non-global domain. I am not sure why that would cause this issue, but I:
- Exported the notification's record to XML
- Updated the domain and domain path fields
- Imported the XML
- Ran the scheduled job
This time, the e-mail was sent. This is the script I ended-up using:
// Select a random number and use it to track the sequence of log messages in this script.
var seq = Math.floor(Math.random() * 999999) + 1;
gs.info('[{0}]GetContacts: Beginning "Get change notification contacts" action in the "Change notification message" flow.', seq++);
// #region Initialize variables
var account = 'bb8083d14755f910291fe0e8036d43ea';
var recpients = 'user1@domain.com,user2@domain.com';
var userList = [];
// #endregion Initialize variables
// #region Get contacts
gs.info('[{0}]GetContacts: Query for active contacts contacts with no location, at {1}.', seq++, account);
var grContact = new GlideRecord('customer_contact');
grContact.addEncodedQuery('account=' + account + '^user_nameISNOTEMPTY^locationISEMPTY^active=true');
grContact.query();
while (grContact.next()) {
//gs.info('[{0}]GetContacts: Adding {1} to the list.', seq++, grContact.getValue('user_name'));
userList.push(grContact.getValue('user_name'));
}
gs.info('[{0}]GetContacts: There are {1} matching contacts.', seq++, userList.length);
// #endregion Get contacts
// #region Trigger event
if (userList.length > 0) {
var userListStr = userList.join('\n');
gs.info("Triggering event to send e-mail.");
gs.eventQueue('send.genericemail', null, recpients, userListStr);
}
// #endregion Trigger event
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2024 12:41 PM
That's odd, everything looks fine, can you also check the following:
- I see the domain field is blurred, is the instance domain separated? If so, does the recipient have access to that domain?
- Review the system log to see if any error log was produced (try triggering the event via background script, that might give you info on the console)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2024 02:15 PM
You need to have the table name selected as contract in the event registration page.
And pass atleast an object here
gs.eventQueue('send.genericemail', null, 'testuser@domain.com', userList.length);
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2024 10:47 AM - edited 05-29-2024 10:52 AM
I set the event registration's table to customer_contact, then changed the scheduled task script. The end of the script now looks like this:
.
.
.
while (grContact.next()) {
//gs.info('[{0}]GetContacts: Adding {1} to the list.', seq++, grContact.getValue('user_name'));
userList.push(grContact.getValue('user_name'));
var record = grContact;
}
gs.info('[{0}]GetContacts: There are {1} contacts.', seq++, userList.length);
// #endregion Get contacts
// #region Trigger event
gs.eventQueue('send.genericemail', record, 'mhashemi@synoptek.com', userList.length);
// #endregion Trigger event
Edit: I ran the job and, when I look at the sysevent list, I see that the Table column shows "customer_contact" and there is a Sys ID in the Instance column, but still no e-mail in the outbox.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-29-2024 10:50 AM
Does it work now?
You can also do
if (grContact)
gs.eventQueue('send.genericemail', grContact, 'mhashemi@synoptek.com', userList.length);
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2024 07:31 AM
Turns out that the notification was in a non-global domain. I am not sure why that would cause this issue, but I:
- Exported the notification's record to XML
- Updated the domain and domain path fields
- Imported the XML
- Ran the scheduled job
This time, the e-mail was sent. This is the script I ended-up using:
// Select a random number and use it to track the sequence of log messages in this script.
var seq = Math.floor(Math.random() * 999999) + 1;
gs.info('[{0}]GetContacts: Beginning "Get change notification contacts" action in the "Change notification message" flow.', seq++);
// #region Initialize variables
var account = 'bb8083d14755f910291fe0e8036d43ea';
var recpients = 'user1@domain.com,user2@domain.com';
var userList = [];
// #endregion Initialize variables
// #region Get contacts
gs.info('[{0}]GetContacts: Query for active contacts contacts with no location, at {1}.', seq++, account);
var grContact = new GlideRecord('customer_contact');
grContact.addEncodedQuery('account=' + account + '^user_nameISNOTEMPTY^locationISEMPTY^active=true');
grContact.query();
while (grContact.next()) {
//gs.info('[{0}]GetContacts: Adding {1} to the list.', seq++, grContact.getValue('user_name'));
userList.push(grContact.getValue('user_name'));
}
gs.info('[{0}]GetContacts: There are {1} matching contacts.', seq++, userList.length);
// #endregion Get contacts
// #region Trigger event
if (userList.length > 0) {
var userListStr = userList.join('\n');
gs.info("Triggering event to send e-mail.");
gs.eventQueue('send.genericemail', null, recpients, userListStr);
}
// #endregion Trigger event