Get users from specific assignment groups (Reference to user table)

Nagashree5
Tera Contributor

Hi All,

 

There is a field called Requested for which references to sys_user table. This field should only show the users who are part of the Admin, Software and Hardware assignment groups.

 

Can anyone guide me on this.

 

Thanks in Advance.

2 REPLIES 2

AshishKM
Kilo Patron
Kilo Patron

Hi @Nagashree5 , 

Write a client script [ onLaod ] on that table for check the logged in user group membership.

 

function onLoad() {
     var usr = g_user.getUserID();
 // set the correct grouop name and add more group using OR || operator
  if (!usr.isMemberOf('<group>')){
    g_form.setVisible("requested_for",false);
 }

or you can write the same logic using the UI Policy

 

-Thanks,
AshishKM 


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

Astik Thombare
Tera Sage

Hi @Nagashree5 ,

 

You need to use Advanced Reference Qualifier to show users which are part of of the Admin, Software and Hardware groups 

 

Create Script Include -

 

AstikThombare_0-1717607486318.png

 

 

var getUsers = Class.create();
getUsers.prototype = {
    initialize: function() {
    },

	getUserSysIds:function(){

var usersList =[];
var gr = new GlideRecord('sys_user_grmember');
var cond = gr.addQuery('group','8a4dde73c6112278017a6a4baf547aa7');// sysId of Software Group
cond.addOrCondition('group','8a5055c9c61122780043563ef53438e3');//sysId of Hardware Group 
// add more condition for admin cond.addOrCondition('group','admin group sys_id');
gr.query();
while(gr.next()){
usersList.push(gr.user.toString());
}
return 'sys_idIN' + usersList;



	},

    type: 'getUsers'
};

 

 

Once this is done Right click on 'Requested for'  field and click on Configure Dictionary -> Click on 'Advanced View' Related Link and Select 'Use reference qualifier' as 'Advanced ' and Paste the below Script 

 

 

javascript&colon; new getUsers().getUserSysIds();

 

 

AstikThombare_1-1717607908499.png

 

Now the Requested for will only show users which are part of mentioned groups 

 

AstikThombare_2-1717607999248.png

 

 

AstikThombare_3-1717608033173.png

 

 

      If my reply helped with your issue please mark helpful 👍 and correct ✔️ if your issue is resolved.

 

                         By doing so you help other community members find resolved questions which may relate to an issue they're having

 

 

Thanks,

 

Astik