CC to respective notification not working as expected
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2024 05:16 AM
Hi experts am trying to trigger respective notification which are selected in list collector variable in catalog item .when RITM is is created on submit notification triggers. Now another one more variable is there like CCGROUP, which is reference to group table. The Notification triggering is working but the cc is not working as expected. Below is my BR script and Notification email script. Thanks in advance.
BR script:
Email script:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2024 05:41 AM
In the BR script, you're setting `groupSysId` from the `cc_group` variable, but this seems to be an individual group rather than a list of group sys_ids. Ensure this variable is being handled as a single `sys_id`, not a list and in the email script, you are splitting `event.parm3` to get `groupSysIds`. However, it appears that `groupSysId` is not being passed as a list of comma-separated sys_ids but as a single `sys_id`. This could cause the email script to iterate over an empty or incorrect list.
Business Rule
(function executeRule(current, previous /*null when async*/) {
var selectedNotificationSysIds = current.variables.template.toString().split(',');
gs.info('Selected Notification SysIds: ' + selectedNotificationSysIds);
var firstNotificationSysId = 'debeea69839c1e146eb8c3b6feaad310';
var secondNotificationSysId = 'c4cc0a2a838c16106eb8c3b6feaad329';
var customEmailBody = current.variables.email_content || '';
// Retrieve the group for CC
var groupSysId = current.variables.cc_group.getValue(); // Ensure this gets a single sys_id
gs.info('Selected CC Group SysId: ' + groupSysId);
// Pass groupSysId as a single value (not as an array)
if (selectedNotificationSysIds.indexOf(firstNotificationSysId) !== -1) {
gs.eventQueue('incident.schedule.reminder', current, groupSysId, customEmailBody);
}
if (selectedNotificationSysIds.indexOf(secondNotificationSysId) !== -1) {
gs.eventQueue('custom.manager.incident.report', current, groupSysId, customEmailBody);
}
})(current, previous);
Update the email script to handle a single `groupSysId` properly instead of splitting it (don't forget to put your own pending logic and template processing in).
(function runMailScript(current, template, email, email_action, event) {
var customEmailBody = event.parm2;
var groupSysId = event.parm3; // Use a single sys_id, not a list
// Get the approver's email address
var approver = new GlideRecord('sys_user');
if (approver.get(current.assigned_to)) {
email.addAddress('to', approver.email);
// Add group members to CC
var groupGR = new GlideRecord('sys_user_grmember');
groupGR.addQuery('group.sys_id', groupSysId); // Query using a single sys_id
groupGR.query();
while (groupGR.next()) {
var emailAddress = groupGR.user.email.toString();
email.addAddress('cc', emailAddress);
}
}
// Handle pending incidents logic here...
template.print(customEmailBody);
// Other template processing here...
})(current, template, email, email_action, event);
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2024 08:23 AM
@Mark Manders I tried by changing script as you given, But in cc according to sysid of group there is only 5 memebers... but when i trigger this script, in cc more than 20 members are there . The event parm3 (sysid) is not passing to mail script I think?