I want to send notification when n number of users added in a group

Amol Pawar
Tera Guru

Hi All,

 

I have a requirement where I need to send two notifications. The first notification I want to send is when 45 members are added to a group and the second notification I want to send is when the 50th member is added to that group.

Adding group members is happening by workflow since it requires approval from admins.

 

Seeking the best and easy approach for this.

 

Thanks in advance,

Amol

 

7 REPLIES 7

Hi @Amol Pawar ,

 

Please refer below script on sys_user_grmrember table

 

HarshalAditya_0-1690526092270.png

 

(function executeRule(current, previous /*null when async*/) {

	var getUserMem = new GlideAggregate("sys_user_grmember");	
	getUserMem.addAggregate("COUNT");
	getUserMem.addQuery("group",current.group);
	getUserMem.query();
	
if (getUserMem.next()){
    var countMem = getUserMem.getAggregate('COUNT');
   if(countMem == 45){
//Trigger event
   }
   else if(conuntMem == 50){
	  //Trigger event 
   }
}

})(current, previous);

 

Please mark this response as correct or helpful if it assisted you with your question.

Regards,
Harshal

 

Amol Pawar
Tera Guru

Hi @Harshal Aditya ,

Thank you for your reply, it was helpful indeed. Below is my working script:

(function executeRule(current, previous /*null when async*/ ) {

    // Add your code here
    var getUserMem = new GlideAggregate("sys_user_grmember");
    getUserMem.addQuery("group.name""your group name");
    getUserMem.addAggregate("COUNT");
    getUserMem.query();

    if (getUserMem.next()) {
        count = getUserMem.getAggregate('COUNT');
        gs.info(count);
        if (count == 3) {
            gs.eventQueue('your event name', getUserMem, '''');
        } else if (count == 19) {
            // gs.eventQueue('');
        }
    }

})(current, previous);
 
It's working as expected, triggering the event but I'm getting one error as "getEventTarget() called with invalid record reference: sys_user_grmember. for event: testingUsersCount, could have been deleted".
Because of this error event is not firing the notification.
 
Please help me resolve this issue.
Thanks and regards,
Amol