- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2020 01:26 AM
Hi
I have requirements : there is a Custom table A and its extending to User table and then i want to check those users roles. Which is in Custom table and How many roles have each user. There is a possibility to repeat the user name in custom table.
Please help me .
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2020 03:24 AM
try with below script. its server side script, you can execute it on business rule .
var fn = current.<field name> ; // which hold the user name
var gr = new GlideRecord('sys_user_has_role');
gr.addQuery('user.name',fn);
gr.query();
gs.log('row count is '+ gr.getRowCount());
while(gr.next()){
if(gr.role.getDisplayValue() != 'approver_req' || gr.getRowCount() == 0){
var grl = new GlideRecord('sys_user_has_role');
grl.initialize();
grl.role = 'approver_req';
grl.user = fn;
grl.insert();
}
}
If my answer helped you, kindly mark it as correct and helpful.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2020 04:37 AM
Thanks For your response.
Ok I am Trying through BR. But its getting row count is 0, i have tried with both BR . after,before .
No Update Because these 4 user has all ready but other users has not updated:
These record are on that table.
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2020 04:48 AM
so it means "Abel tuter" has not any role . can you add script which you have used. so i can check if any thing missed there
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2020 05:50 AM
only i have added the custom field name. u_user_name
var fn = current.u_user_name; // which hold the user name

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2020 05:56 AM
u_user_name is reference type field ?
if yes then update the addQuery part.
gr.addQuery('user',fn);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2020 03:45 AM
Hi Harsh,
Thanks for your support.
Instead of role name i used the sys_id of that role.
grl.role = 'ae52cbcf1b43001060c41067bc4bcb19';
Suppose user have that role by the group. so it will assigned that role to that user also.
is there way to filter.