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

@Ram050670 

 

Open group table and check the type field and check the backend value.

Is the backend value "request"

If yes then please let me know.

Naneen_0-1697567611644.png

Naneen_1-1697567678524.png

 

 

Hello @Ram050670 

 

Use this Script include 

 

 

 getUserRequestGroups: function(userId) {
        var groups = [];
        var gr = new GlideRecord('sys_user_grmember');
        gr.addEncodedQuery('user='+userId+'^group.typeLIKE'+sys_id_of_request record);
        gr.query();
        while (gr.next()) {
            groups.push(gr.group.toString());
        }
        return 'sys_idIN'+groups;
    },

 

Use the sys_id of this record which you have sent on above
Screenshot 2023-10-18 001056.png

 

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

Didn't work!

Naneen_0-1697568673615.pngNaneen_1-1697568729396.pngNaneen_2-1697568753377.png

 

@Ram050670 

sys_id should have to be in '' use like

'ff43cc0c470631104bf90178c26d434f'