Restrict specific user to add attachment/delete the attachment when the case is in closed state

vincentzhen
Tera Contributor

The requirement is restrict the user that belongs to a specific group, they cannot add/delete the attachment for the closed case. What I already try is creating a new business rule in global application, modify it in Attachment table[sys_attachment], before insert and delete and with following script

(function executeRule(current, previous /*null when async*/) {
    // retrieve parent record
	gs.log('Business Rule has been triggered. Record: ' + current.number + " with table name?" + current.table_name);
    var parentRecord = new GlideRecord(current.table_name);
    if (parentRecord.get(current.table_sys_id)) {
        // check case status is closed
        if (parentRecord.getTableName() == 'sn_customerservice_case' && parentRecord.state == 'Closed') {
            // check user is belong to specific user group
            var userGroups = gs.getUser().getMyGroups();
            var restrictedGroup = 'Store';  

            
            if (userGroups.indexOf(restrictedGroup) > -1) {
                gs.addErrorMessage('You are not allowed to add or delete attachments when the case is closed.');
                current.setAbortAction(true);  // prevent to add/delete the attachment
            }
        }
    }
})(current, previous);

 

But still the user still can add/delete the attachment for the closed case...

 

7 REPLIES 7

vincentzhen
Tera Contributor

the way BR works.. however I need to modify the UI pages to hide the attachment icon and delete icon for the attachment part...

vincentzhen
Tera Contributor

OK... it have the store support module, store support user cannot delete/add the attachment when the case closed. When I try is following :

vincentzhen_0-1726688284887.png

And when I impersonate to the store user I still can see the attachment button and delete button..

 

vincentzhen_2-1726688439234.png

 

vincentzhen
Tera Contributor

Kind of urgent for this request.... it looks like somehow I need to change the stuff on service portals side? But now I really lost...