- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2024 08:01 AM
Hi,
I need help on one of my requirement
I have created a group called "test". If any user gets added into the group having 2 roles "itil" , "admin" , then he should be automatically added to the group which i have created called "test" .
@Ankur Bawiskar or @Sohail Khilji can you plz help me on this.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2024 09:27 AM
Hi @karunasrikuna ,
Please check and confirm, are you checking both role or either one is enough for adding user in Test group.
If you are trying to check both roles then AND condition on same addQuery will not work becuase these are two different record and condition applied on same column Role. ( You can try in list view using AND, will not get any record )
The below is working for Role = itil OR Role = Admin and user is adding in test group, you can change the sys_id of this group.
For AND condition, we need to check twice.
(function executeRule(current, previous /*null when async*/) {
// sys_id of itil and admin role, you dont need to change
var strQuery="role=282bf1fac6112285017366cb5f867469^ORrole=2831a114c611228501d4ea6c309d626d";
var grGroupRole = new GlideRecord("sys_group_has_role");
grGroupRole.addQuery("group", current.group);
// filter for role itil and admin, sys_id will be same on all instance
grGroupRole.addQuery(strQuery);
grGroupRole.query();
// check if group has record, the role has AND condition
if(grGroupRole.next()){
var grGroupMember = new GlideRecord("sys_user_grmember");
grGroupMember.initialize();
grGroupMember.group = 'ac416fd4c32f0210339b9dfc05013194'; // sys_id of test group;
grGroupMember.user = current.user;
grGroupMember.insert();
}
})(current, previous);
-Thanks,
AshishKM
Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2024 02:27 PM - edited 07-18-2024 02:27 PM
not with this code.
we have to make that provision using other BR on sys_group_has_role table.
event if user has been removed from any of such group that user should be remove from Test group. ( it all depends what’s the business case )
Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2024 05:01 AM
can you please give me the code to remove the user rom the "test" group , once those 2 roles has been removed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2024 07:34 AM
Sure, give me some time. Please write a new post and share the link here.
Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution