how do I restrict assigned to field if the assignment group is changed to an IT group but the user
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2024 01:38 AM - edited 03-11-2024 01:51 AM
Hello,
I need to restrict the assigned to field if the assignment group is an IT group but the user that is changing the assignment group is not a part of an IT group.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2024 02:10 AM
Hi @achen
You can use Before insert/update Business rule with the following script-
(function executeRule(current) {
var assignmentGroup = current.assignment_group;
var user = gs.getUser();
if (assignmentGroup && user) {
var itGroupId = "ID_of_IT_Group";
// Check if the user belongs to the IT group
var userGroups = user.getGroups();
var isITUser = userGroups.includes(itGroupId);
// If the assignment group is the IT group and the user is not part of IT
if (assignmentGroup == itGroupId && !isITUser) {
current.assigned_to.setReadOnly(true);
gs.addInfoMessage("You are not allowed to change Assigned To for IT groups.");
}
}
})(current);
Please mark my answer helpful and correct.
Regards,
Amit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2024 02:47 AM - edited 03-11-2024 02:49 AM
Hello,
"for var = itGroupID = "ID_of_IT_Group";
would I list this multiple times or can I enter something that says "Name of group starts with = 'SN IT'"
I need to have every IT group in there but they all start with SN IT.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2024 02:45 AM
Hello,
for var = itGroupID = "ID_of_IT_Group";
would I list this multiple times or can I enter something that says "Name of group starts with = 'SN IT'"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2024 03:35 AM
Hi @achen
If there are multiple IT groups, you can modify the script as below-
var assignmentGroup = current.assignment_group; // Get the assignment group
var user = gs.getUser(); // Get the current user
if (assignmentGroup && user) {
var itGroupIds = ["ID_of_IT_Group_1", "ID_of_IT_Group_2"]; // IDs of IT groups
var userGroups = user.getGroups(); // Get groups of the current user
// Check if the assignment group is an IT group and if the user is not part of an IT group
if (itGroupIds.indexOf(assignmentGroup) != -1 && userGroups.indexOf("ID_of_Non_IT_Group") == -1) {
// Restrict Assigned To field
current.assigned_to.setReadOnly(true);
gs.addInfoMessage("You are not allowed to change Assigned To for IT groups.");
}
}
Please mark my answer helpful.
Regards,
Amit