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 User groups list from Requested For

Ram050670
Tera Guru

Hi All,

i would like to get List of groups (type = request) of user from requested for to a reference type field.

can someone help me with Script include and advanced reference qualifier.

 

Naneen_0-1697561192573.png

 

Thanks in advance!

 

1 ACCEPTED SOLUTION

Ram050670
Tera Guru

I would say this is the right way to do it on this request!!


--------------Script Include------------------------

 

getUserRequestGroups: function(userId) {
        var Gtype = gs.getProperty("Assignment_Group_Type");
        var gFilter = gs.getProperty("Assignment_Group_Dynamic_user");
        var groups = [];
        var gr = new GlideRecord('sys_user_grmember');
        gr.addEncodedQuery('group.typeLIKE' + Gtype + '^userDYNAMIC' + gFilter);
        gr.query();
        while (gr.next()) {
            groups.push(gr.group.sys_id.toString());
        }
        return 'sys_idIN' + groups;
    },
 
-----------------------Reference Qualifier-------------------------
 
javascript: new catalogClientUtil().getUserRequestGroups();
 
Naneen_0-1697729170438.png

 

View solution in original post

40 REPLIES 40

Anand Kumar P
Giga Patron

Hi @Ram050670,

Script include script-

getUserRequestGroups: function(userId) {
var groups = [];
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('user', userId);
gr.addQuery('group.type', 'request');
gr.query();
while (gr.next()) {
groups.push(gr.group.toString());
}
return groups;
},

 

Reference qualifier script in user group list field-

javascript: new GroupUtils().getUserRequestGroups(current.user.toString())
Please mark it as solution proposed and helpful if it works for you.

Thanks,

Anand

tried but not working, showing all groups

 

Naneen_0-1697563594617.png

Naneen_1-1697563620414.png

 

Harsh_Deep
Giga Sage
Giga Sage

Hi @Ram050670 

 

Script include script-

 

getUserRequestGroups: function(userId) {

var groups = [];

var gr = new GlideRecord('sys_user_grmember');

gr.addQuery('user', userId);

gr.addQuery('group.type', 'request');

gr.query();

while (gr.next()) {

groups.push(gr.group.toString());

}

return 'sys_idIN'+groups;

},

 

Reference qualifier script in user group list field-

 

javascript: new GroupUtils().getUserRequestGroups(current.variables.name.toString())

 

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.👍

i actually tried that too! req backend is name.

Naneen_0-1697564316116.pngNaneen_1-1697564339222.png