Ankur Bawiskar
Tera Patron

@Community Alums 

try this

var userName = new GlideRecord('sys_user');
userName.addQuery('sys_id', user_id);
userName.query(); // Get logged in user record

var isExcluded = false;

while (userName.next()) {
    var userLoc = userName.location.cmn_location_type; // Get user location type

    var grMem = new GlideRecord('sys_user_grmember');
    grMem.addQuery('user', userName.sys_id);
    grMem.query(); // Find user's groups

    while (grMem.next()) {
        if (grMem.group.name.toString().indexOf("Technical Team") > -1) { // Check if any groups contain "Technical Team"
            isExcluded = true;
            break; // Exit loop if condition found
        }
    }

    if (userLoc == 'X') { // Check if user location type is 'X'
        isExcluded = true;
    }
}

if (!isExcluded) {
    // User meets the criteria
    answer = true;
} else {
    // User does not meet the criteria
    answer = false;
}

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

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