the logged-in user is a member of groups name contains "Nxt". allow to assign INC

varma2
Mega Sage

Hi All.

the logged-in user is a member of any group name contains "Nxt". If they are, then allow them to assign tickets to the following groups
AP-NTT-PS-Support , SAP-T-APO-Support , SAP-N-MII-Support
How can we achieve this trough ACL.

Please provide the some script to achieve this requirement.
 
Rgards
 
 
14 REPLIES 14

Di Zhang
Tera Guru

Here is sample code:

 

answer = false;
var user_id = gs.getUserID();
var sys_user_grmember_gr = GlideRecord('sys_user_grmember');
var query = "user=" + user_id + "^groupLIKENxt";
sys_user_grmember_gr.addEncodeQuery(query);
sys_user_grmember_gr.setLimit(1);
if (sys_user_grmember_gr.next()) {
    answer = true;
}
else {
    answer = false;
}

Mark Manders
Mega Patron

What did you already try and where are you stuck?


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

Hi Mark,

Below script I tried in ACL but its nor working.

 (function() {
    // Define the allowed assignment groups
    var allowedGroups = [
        "SAP-N-PS-Support",
        "SAP-N-APO-Support",
        "SAP-N-MII-Support"
    ];

    // Check if the current user is part of any group with "Nxt" in the name
    var isUserInNxtGroup = false;
    var grMember = new GlideRecord("sys_user_grmember");
    grMember.addQuery("user", gs.getUserID());
    grMember.query();
    while (grMember.next()) {
        var group = grMember.getElement("group").getRefRecord();
        if (group && group.name.toLowerCase().includes("nxt")) {
            isUserInNxtGroup = true;
            break;
        }
    }

    // Deny if not part of a "Nxt" group
    if (!isUserInNxtGroup) {
        return false;
    }

    // If user is in a Nxt group, ensure they are setting an allowed assignment group
    if (current.assignment_group) {
        var assignedGroupName = current.assignment_group.getDisplayValue();
        return allowedGroups.indexOf(assignedGroupName) !== -1;
    }

    return false;
})();
 
Thank you

I think you should know what's the ACL first. ACL can control who can edit the assignment group field but can't set the value of assignment group drop down list. 

Ankur Bawiskar
Tera Patron
Tera Patron

@varma2 

you want to control the record visibility based on table.None READ ACL?

so what debugging did you do in that ACL script?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader