How to grant access(group/role) to user automatically for the users who exists in other custom table

Priya Bonam
Tera Expert

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

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();
  }
}
}