Restrict asset write once a record is created

Vincent Messier
Tera Expert

I have a requirement of letting user with asset roles to be able to create record in alm_asset, but once the record is created they could only edit specific fields like state, substate, location. Only the ham_admin users should be able to edit all the fields in alm_asset.

 

Is this something doable ? 

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

@Vincent Messier 

2 ways to do this

1) ACL approach

you will have to create field level WRITE ACL on those fields to allow edit only in either of these conditions

Record is new

OR

Record is existing and role is not asset role

2) client script approach

Another approach is to have onLoad client script on alm_asset table and check if user has asset role then make all fields read-only and then make state, substate, location as editable

Sample script below

function onLoad() {

    if (g_user.hasRoleExactly('assetRole')) {
        var fields = g_form.getEditableFields();
        for (var x = 0; x < fields.length; x++) {
            g_form.setReadOnly(fields[x], true);
        }

        g_form.setReadOnly('state', false);
        g_form.setReadOnly('sub_state', false);
        g_form.setReadOnly('location', false);
    }
}

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

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

If I go the client script approach, will it only prevent editing in forms or it will also be apply in the list view ?