Skip to content
The Chat Archive
gpt-4o-mini-2024-07-18· OpenAI WildChat-4.8M (AI2)

in servicenow, i want to set approval field value as approved all the time, in ritm form

  1. User

    in servicenow, i want to set approval field value as approved all the time, in ritm form

  2. Assistant

    In ServiceNow, if you want to set the approval field value to "Approved" automatically for all Request Item (RITM) forms, you can accomplish this using a client script or a business rule, depending on when you want to set the value.

    Using a Client Script

    If you want to set the approval value when the form is loaded, you can use a client script. Here’s how to do it:

    1. Navigate to Client Scripts:

      • Go to System Definition > Client Scripts.
    2. Create a New Client Script:

      • Click New.
      • Fill out the form:
        • Name: Set the name for your client script (e.g., "Auto Approve RITM").
        • Table: Choose sc_req_item (for Request Item).
        • UI Type: Choose All or Mobile depending on your needs.
        • Type: Choose onLoad.
    3. Script: Use the following script:

      function onLoad() {
          // Set the approval field to 'approved'
          g_form.setValue('state', '3'); // '3' is typically the value for 'Approved' in the approval state field
      }
      
    4. Save the Script.

    Using a Business Rule

    Alternatively, if you need to set the approval status when a RITM is created or updated, you could use a business rule:

    1. Navigate to Business Rules:

      • Go to System Definition > Business Rules.
    2. Create a New Business Rule:

      • Click New.
      • Fill out the form:
        • Name: Name your business rule (e.g., "Auto Approve RITM").
        • Table: Select sc_req_item.
        • When: Choose before or after based on your needs (usually before for creating).
        • Insert: Check the box to trigger on insert.
        • Update: Optionally check this if you also want it to update existing RITMs.
    3. Condition: If you want to apply this to all RITMs, leave the condition empty or specify any specific criteria you have.

    4. Script: Use the following in the script area:

      (function executeRule(current, previous /*null when async*/) {
          // Set the approval field to 'Approved'
          current.state = 3; // Set the 'state' field to 'Approved' (3)
      })(current, previous);
      
    5. Save the Business Rule.

    Important Note

    1. Data Integrity: Automatically setting the approval status to "Approved" without checking business rules or user's confirmation may lead to issues with service delivery and compliance. Ensure this behavior is acceptable in your organization's workflow.

    2. Approval State Values: The value 3 is commonly used for "Approved" but verify against your specific system's configuration, as custom fields or values may differ.

    Testing

    After implementing your chosen method, create or update a Request Item to verify that the approval state reflects your changes.

    Make sure to adjust the script according to the actual field names in your instance, as they might differ from the standard ServiceNow implementation.