The Zurich release has arrived! Interested in new features and functionalities? Click here for more

roles field in user table

Venkat122
Kilo Guru

Hi All,

There is a field called "Roles" in user table, it appears that there is no value in the field. But, when i filter like roles--is--itil, then it filtered all the users with ITIL role. How values will be copied into this field. Can we rely on this field to report for tickets created by an ITIL user.

Thanks and regards

Giri

13 REPLIES 13

Please go to sys_user table and put filter as roles--is--itil and check whether it is returning ITIL users or not in your personal instance


It will not return and it should not return as well logically as no role data availablel in sys_user for filtering.


Hi Giri,



That is how the relationship is defined and you can perfectly query the user table via roles field.


I have been using roles field on the sys_user table to lock out non-admin users and it works perfectly fine for me.


You can also query multiple roles on the roles field and check the output. It works for me like a charm.



lockoutUsers();



function lockoutUsers() {


      var users = new GlideRecord("sys_user");


      users.addEncodedQuery('active=true^roles!=admin');


      users.query();


      gs.print("User query: " + users.getEncodedQuery() + " = " + users.getRowCount());


      while (users.next()) {


              //Uncomment out the bottom line when you are ready to run this!


              //users.update();


  // users.locked_out = true;


              gs.print(users.getDisplayValue() + " was disabled");


      }


}



This is your encoded query which clearly states that is querying the sys_user_has_role table(view) :



[glide.17] for: SELECT sys_user0.`sys_id` FROM sys_user sys_user0 WHERE sys_user0.`locked_out` = 0 AND sys_user0.`active` = 1 AND sys_user0.`sys_id` IN (SELECT sys_user_has_role0.`user` FROM sys_user_has_role sys_user_has_role0 WHERE sys_user_has_role0.`role` = '2831a114c611228501d4ea6c309d626d')





Regards


Nitin


shruti_tyagi
ServiceNow Employee
ServiceNow Employee

Hi Giri,


Roles field is glide_list field and thats the reason its showing as blank. I would recommend to use 'sys_user_has_role' table this table integrate users and roles.



Thanks


Shruti


If the reply was informational, please like, mark as helpful or mark as correct!


Hi Shruti,



Thanks for your reply !!



when i run the report on roles(like for itil,admin etc.,,) filed it seems like it is returning correct user records.



here requirement is to show the incidents created where caller is an ITIL user. If i query 'sys_user_has_role' then we need to use script include and return all the users with itil role which will cause some performance issues. so, that's why while checking i found that this field is returning the role of the user correctly. I want to confirm on the same as it was not documented any where.



Regards


Swamy