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.

Notification table advance condition

sukran
Mega Sage

Hi All,

Configured email notification ( table as sys_user) table to send users mail notification

We dont want to send certain group and role exclude users  (

Any Idea to add condtion in the advance condition ? saying that group is not xxx and role is not yyy in Notification ( sys_user)

8 REPLIES 8

Thanks @Narsing 

Can we Include parent group name in this script ? like  var parent = group.parent.name ?

 

because In parent group , there are 20+ groups available , which is needs to exclude

Hi,

isMemberOf Function will only accomodate one groupname at a time.  So you need to add the loop seperately. Do like this.

if (gs.getUser().getUserByID(current.sys_id.toString()).hasRole("<role>") || gs.getUser().getUserByID(current.sys_id.toString()).hasRole("<another role>")) {
    var gr = new GlideRecord("sys_user_grmember");
    gr.addQuery("user", current.sys_id.toString());
    gr.query();
    var flagGroup = false;
    while (gr.next()) {
        if (gs.getUser().getUserByID(current.sys_id.toString()).isMemberOf(gr.group.name)) {
            flagGroup = true;
        }
    }
    if (flagGroup) {
        answer = false;
    } else {
        answer = true;
    }
} else {
    answer = false;
}

Thanks,

Narsing

@Narsing  Hats Off and appreciated

 

Let me try this and update you

Hey,

Sorry, I think for your scenario, this code will work. 

var arrBlockedGroups = ["group1", "group2"]; //Mention all your groups here

if (gs.getUser().getUserByID(current.sys_id.toString()).hasRole("<role>") || gs.getUser().getUserByID(current.sys_id.toString()).hasRole("<another role>")) {
    var flagGroup = false;
    for (var m = 0; m < arrBlockedGroups.length; m++) {
        if (gs.getUser().getUserByID(current.sys_id.toString()).isMemberOf(arrBlockedGroups[m].toString())) {
            flagGroup = true;
            break;
        }
    }
    if (flagGroup) {
        answer = false;
    } else {
        answer = true;
    }
} else {
    answer = false;
}

Thanks,

Narsing