Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Add newly added watchlist member to "TO" address of a notification.

Atchutaram
Tera Contributor

I have a requirement to send a notification on incident to  newly added user of watchlist. the newly added user email should be the to address. How can i achieve this? 

 

 

Thanks in advance.

 

3 REPLIES 3

James Chun
Kilo Patron

Hi @Atchutaram,

 

You can trigger an event via a BR when a new user is added to the watchlist.

Include the 'new' user in the event's parameter and you can use it for the notification's recipient.

 

Cheers

Hi @James Chun 

I have done that it is working for one user, but when we add new user its not working here is the code

 

function onBefore(current, previous) {

    // Add your code here
    var array = new ArrayUtil();
    var currArr = current.watch_list.split(',');
    var prevArr = previous.watch_list(',');
    if (array.diff(currArr, prevArr).length > 0) {
        gs.eventQueue('watchlist_add', current, array.diff(currArr, prevArr).toString());
    }

}(current, previous);

Hi @Atchutaram,

 

I would advise using the 'after' Business Rule instead of 'before'.

Below is the modified script:

 

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

    var arrayUtil = new ArrayUtil();
    var currArr = current.watch_list.split(',');
    var prevArr = previous.watch_list.split(',');

    //Find difference bewteen current and previous lists
    var diffArr = arrayUtil.diff(currArr, prevArr);

    //Find 'new' added users only
    var newArr = arrayUtil.intersect(currArr, diffArr);

    if (newArr.length > 0) {
        gs.eventQueue('watchlist_add', current, newArr.join(','));
    }

})(current, previous);