Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Trigger notification for release task

Bhavani1995
Tera Contributor

how to trigger a notification so that assigned user and assigned user delegate and chain of delegates should receive the notification for release task

7 REPLIES 7

I believe OOB it only sends the email to delegated to current recipient.

 

You can achieve this with am email script and add the delegate but I fear that it may end up in a recursive loop when data in delegate table increases.

You ca try gliding the delegate table and get the delegates but it may get struck in infinite loop and send multiple emails.


Please mark the answer correct/helpful accordingly.


Raghav
MVP 2023
LinkedIn

@Bhavani1995 Was this solution helpful?


Please mark the answer correct/helpful accordingly.


Raghav
MVP 2023
LinkedIn

Sarthak Kashyap
Kilo Sage

Hi @Bhavani1995 ,

 

If you have A's Delegate to user B and B's Delegate as User C, Then user B will Receive all Notification of user A but User C will not receive any notification for user A. You can use below script to add user C in notification event. 

 

var recipients = [];

    function getDelegates(userId) {
        var delegateList = [];
        var del = new GlideRecord("sys_user_delegate");
        del.addActiveQuery();
        del.addQuery("user", userId);
        del.query();
        while (del.next()) {
            var delegateId = del.delegate.getValue();
            delegateList.push(delegateId);

            // recursively check if delegate has more delegates
            var nestedDelegates = getDelegates(delegateId);
            delegateList = delegateList.concat(nestedDelegates);
        }
        return delegateList;
    }

    var userA = current.assigned_to; // or whoever is the original recipient
    recipients.push(userA);

    // get all delegates recursively
    var allDelegates = getDelegates(userA);
    recipients = recipients.concat(allDelegates);

    // add recipients to notification
    for (var i = 0; i < recipients.length; i++) {
        gs.eventQueue('custom.notification.event', current, recipients[i], '');
    }

Please mark my answer correct and helpful if this works for you,

Thanks and Regards 

Sarthak