- 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 01:39 AM
Hi,
Is there any reference field in custom table that refer to user table?
If Custom field is there then use GlidedialogWindow api in Client Script
var gr = "user="+caller_id; //write Query here (if user)
var dialog = new GlideDialogWindow("show_list");
dialog.setTitle("Get Role Of User"); //Set the dialog title
dialog.setPreference("table", "sys_user_has_role"); //Pass the table name
dialog.setPreference("sysparm_query",gr);//Pass the query
dialog.render();
Thanks,
Kunal.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2020 01:49 AM
Yes there is one field which is referring the User table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2020 01:51 AM
Hi Kunal,
based on that fields i want to check the users roles

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2020 01:55 AM
Based on that field write onChange() client script use GlideDialogWindow() api.
Make sure that table would be sys_user_has_role
var gr = "user="+newValue; //newValue is reference field of user table.
Mark Correct/Helpful answer if it help you.
Thanks and Regards,
Kunal.