Need to trigger an notification to the Assignment Group, Assigned To, and Watch List in the flow

cp10
Tera Contributor

Hi Team, I have requirement to trigger the email notification to group, assigned to and watch list members and i tried below script action to get the all the recipients but its not getting the sys id in Parm1. Could you please guide me how to fix this issue. Please find the detail doc of flow designer with steps.

 

 

Please see the Script action:

(function execute(inputs, outputs) {
// ... code ...
    var recipients = [];

    // Get the Task record from the Task SLA
    var taskGR = new GlideRecord('task');
    if (taskGR.get(inputs.task)) {

        // Assigned To
        if (taskGR.assigned_to && taskGR.assigned_to.email) {
            recipients.push(taskGR.assigned_to.email);
        }

        // Assignment Group Members
        if (taskGR.assignment_group) {
            var groupMembers = new GlideRecord('sys_user_grmember');
            groupMembers.addQuery('group', taskGR.assignment_group);
            groupMembers.query();
            while (groupMembers.next()) {
                if (groupMembers.user.email) {
                    recipients.push(groupMembers.user.email);
                }
            }
        }

        // Watch List
        if (taskGR.watch_list) {
            var watchList = taskGR.watch_list.split(',');
            for (var i = 0; i < watchList.length; i++) {
                var user = new GlideRecord('sys_user');
                if (user.get(watchList[i]) && user.email) {
                    recipients.push(user.email);
                }
            }
        }
    }

    // Remove duplicates and set Parm1  
var uniqueRecipients = [];
    var seen = {};
    for (var i = 0; i < recipients.length; i++) {
        var email = recipients[i];
        if (!seen[email]) {
            seen[email] = true;
            uniqueRecipients.push(email);
        }
    }
    outputs.parm1 = uniqueRecipients.join(',');


})(inputs, outputs);
2 REPLIES 2

Bhimashankar H
Mega Sage

Hey,

 

Did you checked if it is getting all the recipients email address in outputs.

 

If it is, then just use the code block there and assign to parm1

 

Thanks,
Bhimashankar H

kaushal_snow
Mega Sage

Hi @cp10 ,

 

** I can prefer using Flow designer:


Use a Lookup Records action to query the Assignment Group and Watch List users.

 

Use the Send Notification or Send Email action with data pills:

 

Assigned To.user.email

assignment_group.members.email

record.watch_list (this is a comma-separated string of sys_id values)

 

For Watch List, if you need to add to existing rather than overwrite, concatenate the existing watch_list with new sys_ids in an Update Record action before sending notification...

 

 

Thanks and Regards,
Kaushal Kumar Jha - ServiceNow Consultant - Lets connect on Linkedin: https://www.linkedin.com/in/kaushalkrjha/