Interested in a ServiceNow event built for developers? Registration for now[dev]26 is officially open!

Virtual Agent in MS Teams: only one delegate receives the approval notification when multiple delega

DenysM_
Tera Contributor

If a user sets multiple delegates for approvals over the same time range, all of them should receive the approval notification in Virtual Agent via MS Teams. They don't, because of a bug in getDelegatesForUser() in the MSTeamsNotificationBuilderUtilSNC Script Include. For example, if you delegate your approvals to User1, User2, and User3, the method returns an array like [User1, User1, User1] instead of the three distinct delegates. The script pushes the reference element (delegateGr.delegate) into the array instead of its sys_id value:

 

getDelegatesForUser: function(userId) {
        var ids = [];
        var delegateGr = new GlideRecord("sys_user_delegate");
        var currentDateTime = new GlideDateTime();
        delegateGr.addQuery("starts", "<=", currentDateTime);
        delegateGr.addQuery("ends", ">=", currentDateTime);
        delegateGr.addQuery("approvals", true);
        delegateGr.addQuery("user", userId);
        delegateGr.query();
        while (delegateGr.next()) {
            // put all delegate users in array and return
            ids.push(delegateGr.delegate);
        }
        return ids;
    }
 
Workaround: override the method in MSTeamsNotificationBuilderUtil, which extends the SNC Script Include:

getDelegatesForUser: function(userId) {
        var ids = [];
        var delegateGr = new GlideRecord("sys_user_delegate");
        var currentDateTime = new GlideDateTime();
        delegateGr.addQuery("starts", "<=", currentDateTime);
        delegateGr.addQuery("ends", ">=", currentDateTime);
        delegateGr.addQuery("approvals", true);
        delegateGr.addQuery("user", userId);
        delegateGr.query();
        while (delegateGr.next()) {
            // put all delegate users in array and return
            ids.push(delegateGr.delegate.sys_id.toString());
        }
        return ids;
    }
 
The only change is on the ids.push(...) line, which now pushes the sys_id as a string.
0 REPLIES 0