Skip to content
TheChatArchiveThe Chat Archive
gpt-4o-2024-05-13· OpenAIAi2 WildChat-4.8M (AI2)

Make field read only on form level and prevent it to edit from list view also in…

  1. User

    Make field read only on form level and prevent it to edit from list view also in servicenow

  2. 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

    1. 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.
    2. 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 New to 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 Actions related list and create a new action.
      • Select the field and set Read Only to True.

    Step 2: Make the Field Read-Only in the List View

    1. 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 edit to prevent the field from being edited in the list view.
    2. 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 Write access 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 Write permission to false for necessary roles.
    • 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.