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

Hello @Ram050670 

 

Use this -

 

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

 

As I can see you are using something else.

 

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

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

 

 

GroupUtils() ---- this is script include name right 

Yes if that script include is in the same scope. Otherwise use api name.

 

And as I can see in your given screenshot you have written wrong code.

Use this code -

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.👍

so i made the changes: this is what i am using but shows all list 

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

Hello @Ram050670 

 

Can you please send me all the screen shots, like script include and variable.