Make field read only on form level and prevent it to edit from list view also in…
- User
Make field read only on form level and prevent it to edit from list view also in servicenow
- Assistant
To make a field read-only on a form level and also prevent it from being edited in the list view in ServiceNow, you can follow these steps:
Step 1: Make the Field Read-Only on the Form
-
Navigate to Form Layout
- Go to the application where the field resides (e.g., Incident, Problem, Change).
- Navigate to
System Definition > Dictionary. - Find the field you want to make read-only and open it.
-
Create a UI Policy (optional for form)
- Navigate to the specific module (e.g.,
Incident > All). - Open an existing record or create a new one.
- Right-click the form header and select
Configure > UI Policies. - Click
Newto create a new UI Policy. - Set the condition under which the field should be read-only (e.g., Always if no specific condition).
- Save the UI Policy.
- Go to the
UI Policy Actionsrelated list and create a new action. - Select the field and set
Read OnlytoTrue.
- Navigate to the specific module (e.g.,
Step 2: Make the Field Read-Only in the List View
-
Override the List for the Field
- Navigate to
System UI > List Control. - Find the list control for the table you are working with or create a new one.
- Set the list properties to prevent editing within the list view:
- If the list control does not exist, create a new one.
- Check
Omit editto prevent the field from being edited in the list view.
- Navigate to
-
Client Script (Advanced)
- Sometimes, you may need to ensure further restrictions based on specific conditions. For this, you can add a Client Script.
- Go to
System Definition > Client Scripts. - Create a new Client Script to ensure the field is not editable on the form:
(function executeRule(current, previous /*null when async*/) { // Check for the specific field and condition if required if (current.getTableName() == 'incident' && current.field_name == 'your_field_name') { g_form.setReadOnly('your_field_name', true); } })(current, previous);
Additional Precautions
-
Security Rules: Ensure that no
Writeaccess is provided to that specific field through ACLs (Access Control Rules).- Navigate to
System Security > Access Control (ACL). - Create or modify the ACL for that field and set the
Writepermission to false for necessary roles.
- Navigate to
-
Business Rules or Data Policies: In some cases, you might want to create additional business rules or data policies to enforce the read-only behavior on server-side scripts.
By following these steps, the field should be correctly set to read-only both on the form and list view, ensuring it cannot be edited through either interface.
-