How to grant access(group/role) to user automatically for the users who exists in other custom table
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2023 10:32 PM
Users table = x
custom table = y
Requirement is like query or code should run daily and checks if user exists in custom table then provide access (one group with read only access for custom app) automatically to those users who dont have it already.
5 REPLIES 5
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-25-2023 08:35 AM
Still it is not working as expected.
var Stakeholders = new GlideRecord('u_stakeholders');
Stakeholders.query();
while (Stakeholders.next())
{
var userId = Stakeholders.getValue('u_stakeholders');
var user = new GlideRecord('sys_user');
user.addQuery('name', userId);
user.query();
if (user.next() && !user.isMemberOf('Exxaro ITDR Read User')) {
var groupSysId = f5189ff8db1b24d0da5b75e1f39619fe;
var grUserGroup = new GlideRecord('sys_user_grmember');
grUserGroup.addQuery('group', groupSysId);
grUserGroup.addQuery('user', userId);
grUserGroup.query();
if (!grUserGroup.hasNext()) {
grUserGroup.initialize();
grUserGroup.group = groupSysId;
grUserGroup.user = userId;
grUserGroup.insert();
}
}
}