how do I restrict assigned to field if the assignment group is changed to an IT group but the user

achen
Tera Contributor

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.

4 REPLIES 4

Amit Pandey
Kilo Sage

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

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.  

achen
Tera Contributor

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'"

Amit Pandey
Kilo Sage

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