Need a script to add a user role in sys_user table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-21-2022 01:19 AM
Hi ,
Need a script to add a user role in sys_user table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-21-2022 01:26 AM - edited 12-21-2022 01:27 AM
@Saib1 you can not insert user role in sys_user table, user & role relationships are stored in sys_user_has_role table.
var gr = new GlideRecord('sys_user_has_role');
gr.initialize();
gr.user = ''; // within quotes add sys_id of the user.
gr.role = ''; //within quotes add sys_id of the role.
gr.insert();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-21-2022 01:35 AM - edited 12-21-2022 01:36 AM
Hi @Saib1
Please use the following script:
BR,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-21-2022 02:24 AM
If we want to add Role to Group ? what will be the script?
If we want to remove a Role from Group ? What will be the script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-21-2022 01:43 AM
Hi @Saib1 ,
Try the code below :-
(function() {
var grUserRole = new GlideRecord('sys_user_has_role');
grUserRole.initialize();
grUserRole.user = ''; // sys_id of user record.
grUserRole.role = ''; // sys_id of role record.
grUserRole.insert();
})();
Thanks,
Dhruv