- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2023 02:10 PM
Hi all,
If the group has itil role or if the group contains admin in the role then the custom check box should be checked else it should be unchecked through business rule. If anyone have idea on this could you please help
Thanks in advance
Thanks in advance.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2023 05:22 PM
I would try an after Insert and delete BR on table sys_group_has_role
with condition of
current.role.name.toLowerCase().indexOf('admin') != -1
Not fully tested but something like this should work
var groupCheck = new GlideRecord('sys_user_group');
if (groupCheck.get(current.group)) {
if (current.operation() == 'insert') {
//check the flag and set true if false
if (groupCheck.customField == false) {
gs.info('Group customField was pdated as customField flag is false');
groupCheck.customField = true;
groupCheck.update();
}
}
}
if (current.operation() == 'delete') {
//need to check all roles related to the group and update the flag only if no other 'admin' role left
var selfCheck = new GlideRecord('sys_group_has_role');
selfCheck.addQuery('group', current.group);
selfCheck.addQuery('role.name', 'CONTAINS', 'admin');
selfCheck.setlimit(1);
selfCheck.query();
if (!selfCheck.next()) {
gs.info('Group customField updated as no admin roles exist');
groupCheck.customField = false;
groupCheck.update();
} else {
gs.info('Group customField not updated as an admin role still exists');
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2023 02:21 PM
Hi, normally role assessment is based on the logged in user and unfortunately your post doesn't provide context for your requirements meaning what\how\why is not clear.
If you want to evaluate a 'group' for relationship to a role, you would need to run a GlideRecord query against table 'sys_group_has_role' looking for a match of group and role, if found then set your checkbox to true.
Perhaps you can update your post with some clear and specific details of your business requirement, the underpinning drivers for the requirement and the related operational process(es) so that the forum can better understand your configuration and expectations.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2023 02:33 PM - edited 04-11-2023 02:34 PM
Hi Tony ,
In sys_user_group table we have a custom field called hasrole and its a checkbox. So now if we add itil role or role containing admin in its name the custom field should be checked and if we remove itil role it should be unchecked. Could you please provide the script for this
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2023 05:22 PM
I would try an after Insert and delete BR on table sys_group_has_role
with condition of
current.role.name.toLowerCase().indexOf('admin') != -1
Not fully tested but something like this should work
var groupCheck = new GlideRecord('sys_user_group');
if (groupCheck.get(current.group)) {
if (current.operation() == 'insert') {
//check the flag and set true if false
if (groupCheck.customField == false) {
gs.info('Group customField was pdated as customField flag is false');
groupCheck.customField = true;
groupCheck.update();
}
}
}
if (current.operation() == 'delete') {
//need to check all roles related to the group and update the flag only if no other 'admin' role left
var selfCheck = new GlideRecord('sys_group_has_role');
selfCheck.addQuery('group', current.group);
selfCheck.addQuery('role.name', 'CONTAINS', 'admin');
selfCheck.setlimit(1);
selfCheck.query();
if (!selfCheck.next()) {
gs.info('Group customField updated as no admin roles exist');
groupCheck.customField = false;
groupCheck.update();
} else {
gs.info('Group customField not updated as an admin role still exists');
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2023 05:56 PM
Hi Tony,
Thanks a lot it is working has expected.