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.

Get group members email address from glide list field.

ESL
ServiceNow Employee
ServiceNow Employee

Hi  

I have a glide list in the form which is a list of user groups.
I need to get all user's email address from the groups in the list by script (business rule or something), any Idea to do that? 
Please advice. Thanks

find_real_file.png

1 ACCEPTED SOLUTION

Jaspal Singh
Mega Patron
Mega Patron

You can try someting as below as a business rule on required table that runs before update with script as below

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

    var getlistis = current.abcd.split(','); //replace abcd with your glidelist field name
    for (var i = 0; i < getlistis.length; i++) {
        var grmembers = new GlideRecord('sys_user_grmember');
        grmembers.addQuery('group', getlistis[i]);
        grmembers.query();
        while (grmembers.next()) {
            current.description = current.description + ',' + grmembers.user.getDisplayValue();
        
//replace current.description with value  you want to get the users list on
}

    }
})(current, previous);

View solution in original post

2 REPLIES 2

Jaspal Singh
Mega Patron
Mega Patron

You can try someting as below as a business rule on required table that runs before update with script as below

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

    var getlistis = current.abcd.split(','); //replace abcd with your glidelist field name
    for (var i = 0; i < getlistis.length; i++) {
        var grmembers = new GlideRecord('sys_user_grmember');
        grmembers.addQuery('group', getlistis[i]);
        grmembers.query();
        while (grmembers.next()) {
            current.description = current.description + ',' + grmembers.user.getDisplayValue();
        
//replace current.description with value  you want to get the users list on
}

    }
})(current, previous);

ESL
ServiceNow Employee
ServiceNow Employee

Jaspal 

Thanks, Your script is very helpful.

I just modified a little bit adding ".email" to get user's email information.

Thanks a lot!

            current.description = current.description + ',' + grmembers.user.email.getDisplayValue();