gs.eventqueue is not working on internal users
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2024 11:08 PM
I created business rule that get the additional assignee list for a record and extract every Internal user and then trigger a gs.eventQueue to send notification.
the weird thing is that its not sending to internal users. when I add a custom email address it works.
business rule :
(function executeRule(current, previous /*null when async*/ ) {
// Assuming your input string is stored in a variable called 'inputString'
var inputString = current.additional_assignee_list;
// Split the input string by comma to get individual entries
var entriesArray = inputString.split(',');
var emailArray = [];
var numberArray = [];
// Validate and classify entries
for (var i = 0; i < entriesArray.length; i++) {
var entry = entriesArray[i].trim();
// Regex to validate email
var emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (emailRegex.test(entry)) {
// It's a valid email, add to emailArray
emailArray.push(entry);
} else if (entry !== "") {
// It's a valid number, add to numberArray
numberArray.push(entry);
} else {
// Handle invalid entries if required
gs.info("Invalid entry: " + entry);
}
}
// Create a comma-separated string of numbers
for (var j = 0; j < numberArray.length; j++) {
var number = numberArray[j];
var user_email = GlideRecord('sys_user');
user_email.get(numberArray[j]);
var nametest = user_email.email;
gs.eventQueue('dop_notification_new_comment_internal', current, user_email.sys_id );
gs.info("Number sent: " + user_email.email);
}
})(current, previous);
Tried user_email.email , user_email , user_email.user_name.
nothing worked on internal users. tried also to string, same thing.
the busines rule and the notification works fine because if I change this "...user_email.sys_id);"
with custom email it works
also the gs info gives me the email of the user so it also works fine
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2024 11:47 PM
It looks like your script works perfectly based on my test. I was able to fire the event, and the event triggered the notification as expected.
To confirm if the event fired successfully on your instance, have you checked the event queue? You can do that here:
Sample: https://<instance_name>.service-now.com/sysevent_list.do?sysparm_query=nameSTARTSWITHdop_notification_new_comment_internal
Additionally, is there a specific requirement for sending emails to the additional assignees one by one? If not, you can simply get the value of additional_assignee_list and fire the event (no need to do a query to User table). The notification should handle both User sys_id and Email address directly from the event parm.
Cheers,
Tai Vu