Make assignment group and assigned to fields editable only to admin and incident manager. For others these fields should be readonly

Shraddha desai
Tera Contributor

Make assignment group and assigned to fields editable only to admin and incident manager. For others these fields should be readonly.

How can I do this from client script ?

3 REPLIES 3

Shiva Kumar8
Kilo Guru

You need to use Access Control lists to achieve this please create ACL's with conditions on respective table where you want to make those fields read only for other users and the other approach is client script below

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading) {
        return;
    }

if(g_user.hasRoleExactly('admin') || g_user.hasRoleExactly('incident_manager')){

if(g_form.getValue('assignment_group') == false && g_form.getValue('assigned_to') == false){

// field editable

}

else{

// field readonly

}

}

}

Voona Rohila
Kilo Patron
Kilo Patron

Hi Shraddha

This can be achieved Using client scripts,and ACL's.

Client script: You can write onLoad client script, check if user has particular roles and set readonly to true.

function onLoad(){
if(g_user.hasRoles('itil','incident_manager')){
g_form.setReadOnly('field1', true);
g_form.setReadOnly('field2', true);
}
}

ACL's - you need 2 write ACL's so that anywhere they are trying to edit those fields, the acl's will restrict the write access.

 


Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP

Could you please show the demo.?