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

Naneen_0-1697565334375.pngNaneen_1-1697565352870.png

Naneen_2-1697565382387.png

 

Hello @Ram050670 

 

In the Reference qualifier don't use javascript: new 

 

Use this-

Screenshot_2023-10-17-23-14-40-98_40deb401b9ffe8e1df2f1cc5ba480b12.jpg

 

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

hI @Ram050670;
Update your Reference Qualifier to :

 

 

javascript: new CatalogClientUtil().getUserRequestGroups(current.variables.requested_for.toString())

 

Don't put : put actual colon

tried this too! didn't work.

@Ram050670,
Update your Script Include to return 'sys_idIN'+groups;

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;

},