Need to check login user is member of Analytics, Managers (assignment group).

praveen1231
Tera Contributor

Hello everyone,

I need to ensure that a ticket can only be submitted if the logged-in user is a member of any one of the following groups: Analytics, Managers, App Engine Admins, or App Engine Studio. For example, if the user selects an assignment group as Change Management, logged-in must be a member of Change Management and above mentioned groups. If the user does not belong to any of these groups and the selected assignment group, they should not be able to submit the ticket. A warning message should be displayed to the user before submission to indicate this restriction. Please help me to solve this work. This is high priority task. Thank you.

 

Best Regards,

Praveen Rajan

8 REPLIES 8

Sid_Takali
Kilo Patron
Kilo Patron

Hi @praveen1231 try Before Insert/Update BR 

(function executeRule(current, previous /*null when async*/) {
    var allowedGroups = ['Analytics', 'Managers', 'App Engine Admins', 'App Engine Studio'];
    var user = gs.getUser();
    var userGroups = user.getMyGroups();
    
    var isUserInAllowedGroup = false;
    for (var i = 0; i < userGroups.length; i++) {
        if (allowedGroups.indexOf(userGroups[i].name) !== -1) {
            isUserInAllowedGroup = true;
            break;
        }
    }
    
    var selectedGroup = current.assignment_group.getDisplayValue();
    if (isUserInAllowedGroup || userGroups.indexOf(selectedGroup) !== -1) {
        return; 
    }
    
    gs.addErrorMessage('You must be a member of one of the following groups to submit this ticket: Analytics, Managers, App Engine Admins, or App Engine Studio, and the selected assignment group.');
    current.setAbortAction(true); 
})(current, previous);

Hi @Sid_Takali Thanks for your valuable timing. But it not working as we expected.

praveen1231_0-1723033377814.png

In the provided image, the logged-in user is identified as a system administrator, and the assignment group selected is "App Engine Admins." Despite this, an error is being reported stating that the system administrator does not belong to the "App Engine Admins" group.

praveen1231_1-1723033531334.png

I’ve already added the System Admin as a member of the "App Engine Admins" group. Could you please verify why the script is not recognizing this group membership?



Hi @praveen1231 In the array add the sys_id of the group 

 var allowedGroups = ['Analytics', 'Managers', 'App Engine Admins', 'App Engine Studio'];

Hi @Sid_Takali Facing same error again.