restrict new button on workspace

VSN
Tera Expert

i am working on employee table in  configuration workspace,

my requirement is if employee table record state is completed or canceled states,then employee_manager and employee_owner roles not able to create a new record in related lists those attached to employee table.

.most linky to restrict new button on related lists of employee table.

prefered was is ACL..

 

1 REPLY 1

Community Alums
Not applicable

Hi @VSN ,

 

Please use the below code snippet in the ACL(Create type) script(Ensure you enable the Advance on ACL to write the script)

(function executeRule(current, operation, previous /*null when 'create'*/) {
    // Get the parent Employee record based on the relationship field
    var employeeRecord = new GlideRecord('employee_table');
    employeeRecord.get(current.parent);  // Replace 'parent' with the actual field name that references the Employee table

    // Check if the Employee record's state is either 'Completed' or 'Canceled'
    if (employeeRecord.state == 'completed' || employeeRecord.state == 'canceled') {
        // Check if the user has 'employee_manager' or 'employee_owner' roles
        if (gs.hasRole('employee_manager') || gs.hasRole('employee_owner')) {
            return false;  // Denies create permission
        }
    }
    return true;  // Allows others to create records
})(current, operation, previous);

 

If my response has resolved your query, please consider giving it a thumbs up ā€Œā€Œ and marking it as the correct answerā€Œā€Œ!

 

Thanks & Regards,

Sanjay Kumar