- 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 01:01 AM - edited 02-09-2024 02:41 AM
This has worked - is there a way to update it so that if the user has the admin role, it will work for them?
Edit: Ignore me, I added !gs.role('admin') to the condition above the script.
Edit 2: Upon activation, this is preventing any group from being assigned to, not just the group mentioned, my version of the script which I've updated the group name to is below:
// Condition: !gs.hasRole('admin')
(function executeRule(current, previous /*null when async*/ ) {
// Check if the current user is a member of NHSL-SN-ServiceDeskEnquiries
var currentUser = gs.getUser();
var groupMembership = new GlideRecord('sys_user_grmember');
groupMembership.addQuery('group', 'NHSL-SN-ServiceDeskEnquiries'); // Adjust the group name as needed
groupMembership.addQuery('user', currentUser.getID());
groupMembership.query();
// If the current user is not a member of NHSL-SN-ServiceDeskEnquiries, 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 authorised to assign to this group.');
}
})(current, previous);
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-08-2024 06:15 AM - edited 02-08-2024 06:33 AM
Hi @Wasdom_Kung ,
1. You can use below onChange client script and script include.
1. OnChange Client Script:
Type : onChange
Field Name: Assignment Group
Script:
Screenshot:
2. Script Include:
Please hit the like button if my suggestion has helped you in any way.
Please mark correct if my response has solved your query.
Thanks & Regards
Jyoti Jadhav