Creating individual notifications for a glide_list of users

Ishenferi
Tera Contributor

Hello!

 

I'm trying to create a notification based on who is populated between two glide lists:

Users Group A

Users Group B

 

I'm also trying to figure out if there's a simple(ish) way to script it that only new additions to either field trigger the email again. For example, if Users Group A has User1 and User2, they would get the notification. But, if at a later point User3 was added, only User3 would receive a new notification.

 

Note, I am not a developer, so please use simple words with me.

 

Thanks! 🙂

3 REPLIES 3

AshishKM
Kilo Patron
Kilo Patron

Hi @Ishenferi

I dont think this is possible under current OOTB notification configuration.

As you said new User3 should receive notification not the User1 & User2 but at what level we can achive lets assume there is User4 added at some point of time and User5, User6 ... as so on.

 

-Thanks,
AshishKM


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

Its_Azar
Tera Guru

Hi there @Ishenferi 

 

You can do tgis by creating a Business Rule that triggers notifications for new additions to your Glide Lists. 

first create a Business Rule: Navigate to System Definition > Business Rules and create a new rule for the table containing your Glide Lists (Users Group A and Users Group B). Set it to run "After Update".

Script for New Users: In the Business Rule script, compare the previous and current values of the Glide Lists to identify new users. Here's a sample script to get you started:

 

 

(function executeRule(current, previous) {
    var newUsersA = getNewUsers(current.users_group_a, previous.users_group_a);
    var newUsersB = getNewUsers(current.users_group_b, previous.users_group_b);

    var newUsers = newUsersA.concat(newUsersB);

    sendNotifications(newUsers);

    function getNewUsers(currentList, previousList) {
        var newUsers = [];
        var currentUsers = currentList.split(',');
        var previousUsers = previousList.split(',');

        for (var i = 0; i < currentUsers.length; i++) {
            if (previousUsers.indexOf(currentUsers[i]) === -1) {
                newUsers.push(currentUsers[i]);
            }
        }
        return newUsers;
    }

    function sendNotifications(userList) {
        for (var i = 0; i < userList.length; i++) {
            var user = new GlideRecord('sys_user');
            if (user.get(userList[i])) {
                gs.eventQueue('notify.new.user', current, user.sys_id, user.email);
            }
        }
    }
})(current, previous);

 

 

Go to System Policy > Events > Event Registry and create a new event called notify.new.user.

Navigate to System Notification > Email > Notifications and set up a new notification to be triggered by the notify.new.user event. Configure the recipient as Event Parm 2 (Email) and customize your email content accordingly.

 

Kindly accept the answer if this helps thanks.

☑️ If this helped, please mark it as Helpful or Accept Solution so others can find the answer too.




Kind Regards,

Mohamed Azarudeen Z

Developer @ KPMG

 Microsoft MVP (AI Services), India

Hey Azar,

 

That works out wonderfully, I just had one last question associated. Is there a way to individually address the emails when they're split this way?

 

For example, if User1, User2, and User3 are added, is there a way to add "Hello User1", "Hello User2", "Hello User3" to their respective emails?