Notification to users in a list collector

Cirrus
Kilo Sage

Hi,

Can anyone advise if there is a way to do this please. 

We have a list field on a form, and we want to send a notification to the users in the list when someone new is added. However, we only want to send the notification to the original users in the list, and exclude the new user.

I have created a Before Update BR below which triggers the notification, but it sends it to the new user as well.

Is there a way we can exclude the new user from receiving the notification?

 

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

    var getListusers = current.collaborators.toString();
    var splitusers = getListusers.split(',');
    for(var i=0;i<splitusers.length;i++){
        gs.eventQueue('collaborators.updated',current,splitusers[i]);
    }

})(current, previous);
1 ACCEPTED SOLUTION

Hi @Cirrus , try this - 

var pre = previous.watch_list;
	var cur = current.watch_list;
	var preArr = pre.split(',');
	var currArr = cur.split(',');
	var difference = new global.ArrayUtil().diff(currArr , preArr);
	gs.eventQueue('test.notify',current,difference.toString());

This way, even if someone is removed from the list, a notification will not be sent.

View solution in original post

9 REPLIES 9

Anurag Tripathi
Mega Patron
Mega Patron

Hi Cirrus,

 

Leave the code from a second now, can you just explain how you differentiate original users and new?
What happens if I add users to that list 3 times.

-Anurag

Anurag, I can see where you are coming from. We are assuming that the 'submitter' would only lock the list once the 3 new users had been added and then save the form. If they saved after each addition, then I would expect the number of notifications to be 1, 1+1,1+2 for each user added. Looks like using previous.collaborators does what we need. Thanks for your time to look at this

GopikaP
Mega Sage

Hi @Cirrus , 

Can you try this - in the second line instead of 'current', use 'previous' (var getListusers = previous.collaborators.toString();)

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

    var getListusers = previous.collaborators.toString();
    var splitusers = getListusers.split(',');
    for(var i=0;i<splitusers.length;i++){
        gs.eventQueue('collaborators.updated',current,splitusers[i]);
    }

})(current, previous);

Thanks, using previous does what we need. Now in reverse, is there a way to single out the new user so we can notify them that they have been added?