- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2024 05:11 AM
Hello,
I have been asked to 'lock down' an assignment group, this group can be viewed from the assignment group field on the incident form (We already have this set to only display specific groups that match 'types' set in the dictionary).
I am looking to implement the following: If someone is in the group (say Group 1) then check if this user is also in that group on submission of the incident, if not clear the field and display an error. If they are in the group on submission, keep populated and save incident.
How could I achieve this? Or if someone has done something similar, that'd be great!
Thanks,
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2024 06:01 AM
Hi @Wasdom_Kung, If you want to restrict the incident creation when the logged in user is not part of the assignment group, you can create a Before Insert Business Rule.
(function executeRule(current, previous /*null when async*/ ) {
if (!gs.getUser().isMemberOf(current.assignment_group)) {
gs.addErrorMessage("You are not an member of Assignemt group.");
current.setAbortAction(true);
}
})(current, previous);
Regards,
Sunil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2024 03:16 AM
Removed my previous comment, had the wrong attempt in it.
I've added the following condition, but it seems to evaluate false as the BR isn't running:
current.assignment_group == 'NHSL-SN-ServiceDeskEnquiries'
Code:
(function executeRule(current, previous /*null when async*/) {
function checkGroupMembership(group, user) {
var gr = new GlideRecord("sys_user_grmember");
gr.addQuery("group", group);
gr.addQuery("user", user);
gr.query();
if (gr.hasNext()) {
return true;
} else {
return false;
}
}
if (checkGroupMembership(current.assignment_group, gs.getUserID()) == false) {
gs.addErrorMessage("You are not authorised to assign to this group.");
current.setAbortAction(true);
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2024 06:01 AM
Hi @Wasdom_Kung, If you want to restrict the incident creation when the logged in user is not part of the assignment group, you can create a Before Insert Business Rule.
(function executeRule(current, previous /*null when async*/ ) {
if (!gs.getUser().isMemberOf(current.assignment_group)) {
gs.addErrorMessage("You are not an member of Assignemt group.");
current.setAbortAction(true);
}
})(current, previous);
Regards,
Sunil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2024 03:17 AM - edited 02-09-2024 04:24 AM
I attempted this with the following condition, however it always seems to evaluate as false:
current.assignment_group == 'NHSL-SN-ServiceDeskEnquiries'
Edit: I used filter conditions instead and this is now working, thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2024 06:05 AM
Are you trying to check whether logged in user is part of the mentioned group?
or you have some user field in Incident table and you want to check whether that user in particular group.
you can check if user is present in particular group by using below script in before insert/update business rule
var userRec = new GlideRecord('sys_user_grmember');
userRec.addQuery('group',current.assignment_group);
userRec.addQuery('user',current.fieldname);// field in which user record is stored
userRec.query();
if(userRec.next()){
gs.addInfoMessage('User present');
}
else{
current.assignment_group ='';
gs.addErrorMessage('User not present');
}
if you are checking logged user's membership in group, then you can use below script
if(gs.getUser().isMemberOf('groupname')){
gs.addInfoMessage('user present in group');
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2024 06:11 AM
// Check if the current user is a member of Group 1
var currentUser = gs.getUser();
var groupMembership = new GlideRecord('sys_user_grmember');
groupMembership.addQuery('group', 'Group 1'); // Adjust the group name as needed
groupMembership.addQuery('user', currentUser.getID());
groupMembership.query();
// If the current user is not a member of Group 1, clear the assignment group field and display an error
if (!groupMembership.hasNext()) {
current.assignment_group.clearValue();
current.assignment_group.setDisplayValue('');
gs.addErrorMessage('You are not authorized to assign to this group.');
}
}
You can use the above before BR for insert/update.
Regards,
Amit
Note- Please mark my response as Correct/Helpful.