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

cp10
Tera Contributor

Hi @Ankur Bawiskar, 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);
1 REPLY 1

Uncle Rob
Kilo Patron

Why are you doing this via script?   You can define a notification, and then have the flow launch that.
I did a video on it.  
This link takes you to the exact start time of the Notification activity explainer
https://youtu.be/FtOT4aDs7lo?si=WJc7clLeVN__byrf&t=323