Define ServiceNow AI Lens behavior with Lens actions

  • Freigeben Version: Australia
  • Aktualisiert 12. März 2026
  • 20 Minuten Lesedauer
  • As a Lens admin, you can create Lens actions in ServiceNow AI Lens to customize Lens behavior by providing default instructions, configuring context, and more.

    Use Lens actions to define default instructions, trigger options, custom context, and post processing instructions for the Lens response. With Lens actions, you can achieve the following goals:
    • Trigger ServiceNow AI Lens from a desktop, ServiceNow instance, or Virtual Agent (from a mobile device or a portal)
    • Auto-fill a form on the ServiceNow instance
    • View the gathered insights in an editable preview
    • Trigger flows, subflows, or actions after Lens execution
    • Invoke AI agents
    • Run ServiceNow AI Lens as a back-end service
    • Auto-map the column headers of an Excel sheet with the columns of a ServiceNow table, and then insert the Excel sheet data into the ServiceNow table.

    Whenever ServiceNow AI Lens is launched from an instance, it checks if any active Lens action is available for the table. If available, it uses the logic defined in Lens action during execution. The Lens action can only be used by the users or groups or roles that are assigned to the Lens Actions record.

    Refer to the following examples to understand the different use cases of setting up the Lens actions.

    Customize ServiceNow AI Lens behavior by creating a Lens action

    Create a Lens action to define custom context, trigger options, and default instructions for the ServiceNow AI Lens execution.

    Vorbereitungen

    Role required: lens_admin

    Warum und wann dieser Vorgang ausgeführt wird

    Learn about the various Lens trigger options for ServiceNow AI Lens.

    Tabelle : 1. Lens trigger options
    Goal Trigger From Trigger For
    Auto-fill a form with a custom context and default instructions when triggered from the instance.

    When ServiceNow AI Lens is triggered from the instance in the context of the Lens action, the default instructions are always applied and specific form fields are extracted.

    To view the procedure to define default instructions, see Define default instructions for ServiceNow AI Lens.

    Instance Form
    Auto-fill a form with a custom context and default instructions when triggered from the ServiceNow AI Lens desktop app.

    You can trigger ServiceNow AI Lens from the desktop app directly in context of the Lens action instead of launching Lens from the instance. The default instructions are always applied and specific form fields are extracted.

    Desktop Form
    Auto-map the column headers of an Excel sheet with the columns of a specified table, and then insert the Excel sheet data into the table.

    To view the procedure to auto-map the column headers of an Excel sheet with the columns of a table, and insert Excel data into the table, see Auto-map Excel sheet column headers with table columns.

    Desktop Excel Mapping
    With the help of a client script or server script, run ServiceNow AI Lens as a back-end service. Instance Service
    View the gathered insights in the preview window of ServiceNow AI Lens by providing custom context and perform post processing steps. Desktop Others

    When ServiceNow AI Lens is triggered from the instance or desktop to auto-fill a form, it uses an active Lens action associated with the target table.

    For example, if a user selects Create with Lens from Incident table list, ServiceNow AI Lens checks for an active Lens action record for the Incident table where Trigger From is set to Instance and Trigger For is set to Form. If a matching action record exists, Lens executes in the context of that action.

    Prozedur

    1. Navigate to All > ServiceNow AI Lens > Lens Actions.
    2. Select New.
    3. Enter a name and description for the Lens action in the Name and Description fields respectively.
    4. In the Trigger From field, select one of the following options.
      OptionDescription
      Desktop Option to specify that this action must be used when ServiceNow AI Lens is triggered from the ServiceNow AI Lens desktop app.
      Instance Option to specify that this action must be used when ServiceNow AI Lens is triggered from a ServiceNow instance.
    5. To save the changes, right-click the form header and select Save.
    6. Set up the Lens action by filling the fields in the Lens Actions form, under the Customize heading.
      Tabelle : 2. Lens Actions form
      Field Description
      Trigger For
      • Form - Lens action is used when ServiceNow AI Lens is triggered to auto-fill a form. Apply a transformation logic to the Lens response before the form is auto-filled by using the servicenow-lens-actions.html#create-sn-lens-recipe__transform-response option.

        This option is available when you select Desktop or Instance from the Trigger From list.

      • Service - Lens action is used when ServiceNow AI Lens is used as a service. Select this option to trigger Lens from an instance to auto-populate a Workspace form, or to trigger it using Virtual Agent or Script Include.

        This option is available when you select Instance from the Trigger From list.

      • Others - Lens action is used when ServiceNow AI Lens is triggered to display a preview of extracted data and perform post processing steps, if applicable.

        This option is available when you select Desktop from the Trigger From list.

      • Excel Mapping -

        Option to specify that you can use this Lens action to attach an Excel sheet and let ServiceNow AI Lens auto-map its column headers with the columns of a table. After the auto-mapping is done, you can view and change the mapping, and insert the Excel sheet data to the table.

        This option is available when you select Desktop from the Trigger From list.

      Order Execution priority of the Lens action for a given table:
      • 1: Highest priority
      • 999999: Least priority

      The default value is set to 100.

      For example, if any user is assigned to two Lens action records for the same table, the Lens action with the least number is used during Lens execution.

      Table Table to which this Lens action applies. Selected table provides context during Lens execution when specific fields are selected or script is provided.

      For example, Incident table.

      Request Context Option to provide enhanced context during Lens execution by selecting specific fields or providing custom schema via script.
      • Supported Fields - Selected fields for providing enhanced context for Lens execution.
      • Advanced - Script to generate a custom schema object for providing enhanced context for Lens execution.
      Fields Table fields that you can select to provide enhanced context for Lens execution. Select fields to help Lens determine what information to extract from images. Only fields supported by Lens are available for selection. For more information, see Field types supported.

      This field appears only when Supported Fields is selected from the Request Context choice field.

      Pre Processing Script Script to generate a custom schema object to provide enhanced context for Lens execution. Custom schema help Lens determine what information to extract from images.

      This field appears only when Advanced is selected from the Request Context choice field.

      Example sample script:

      function preProcessRequest(lensActionRecord, inputJSON) {
          // Initialize the schema object
          var schemaObj = {};
          /*
          This is a utility method to generate schema object, 
          users can pass tableName and formFields as an array of fields for the given table to generate custom schema that is passed to the LLM.
          
          //Return schemaObj adhering to the structure defined in example
          // tableName = 'incident'
          tableName = inputJSON.tableName; 
      
          //formFields - array of fields for the given table.
          //formFields = ['short_description', 'comments', 'impact'];
          
          fieldsToProcess = inputJSON.formFields;
          schemaObj = new global.AILensSchemaUtil().generateSchema(tableName, fieldsToProcess);
      
          */
          return schemaObj;
      }
      var schemaObj = preProcessRequest(lensActionRecord, inputJSON);
      Parameters accepted by the preProcessRequest method:
      • lensActionRecord (Input) - GlideRecord of the Lens action that is executed.
      • inputJSON (Input) - Optional JSON object that users can pass through service APIs.
      • schemaObj (Output) - Returned JSON object of custom schema.

      Example of the returned schemaObj object:

      schemaObj =  {
        "schemaPayload": {
          "type": "json_schema",
          "json_schema": {
            "name": "schema_extraction",
            "schema": {
              "type": "object",
              "properties": {
                "short_description": {
                  "type": "string",
                  "label": "Short description"
                },
                "comments": {
                  "type": "string",
                  "label": "Additional comments"
                },
                "impact": {
                  "type": "choice",
                  "label": "Impact",
                  "choiceValues": ["1", "2", "3"],
                  "choiceLabels": {
                    "1 - High": "1",
                    "2 - Medium": "2",
                    "3 - Low": "3"
                  }
                }
              },
              "required": [
                "short_description",
                "comments",
                "impact"
              ],
              "additionalProperties": false
            }
          }
        },
        "fieldLabels": ["short_description", "comments", "impact"]  //Optional key
      }
      Default Additional Directions Default instructions that are supplied to Now Assist in addition to the user-provided instructions.

      For example, Summarize this paper by extracting the title, author name, publication date in the dd-mm-yyyy format, abstract, and keywords

      Transform Response Option to specify the transformation script for transforming the Lens response before auto-filling the form.

      This field appears only when Form is selected from the Trigger For choice field.

      Transformation Script Script that transforms the Lens response before populating the form.

      This field appears only when the Transform Response option is selected.

      Sample script:

      function transformResponseScript(lensActionRecord, lensResponse) {
         // Initialize the schema object
          var transformResponse = {};
          
          //Add your code here
          
          //Return schemaObj adhering to the structure defined in example
          return transformResponse;
      }
      var transformResponse = transformResponseScript(lensActionRecord, lensResponse);
      Parameters accepted by the transformResponseScript method:
      • lensActionRecord (Input) - GlideRecord of the Lens action that is executed.
      • lensResponse (Input) - JSON object of the Lens response provided after Lens execution.
      • transformResponse (Output) - Returned JSON object of transformed schema.

      Example of the returned transformResponse object:

      transformResponse = {
        "short_description": "Service Degradation Error in Order Processing System",
        "description": "The Order Processing API v2.1 encountered a service degradation issue in the Production environment",
        "urgency": "1"
      }
      Enable Post Processing Option to specify advanced processing instructions after Lens execution is complete.

      This field appears only when Others or Service is selected from the Trigger For field.

      Post Processing Script Script that is run asynchronously after Lens execution to further process the Lens response, such as triggering a flow, subflow, actions, or AI Agent.

      This field appears only when the Enable Post Processing option is selected.

      function postProcessResponse(lensActionRecord, lensResponse, lensExecutionRecord) {
          
          //Add your code here
      
      }
      postProcessResponse(lensActionRecord, lensResponse, lensExecutionRecord);
      Parameters accepted by the postProcessResponse method:
      • lensActionRecord (Input) - GlideRecord of the Lens action that is executed.
      • lensResponse (Input) - JSON object of the Lens response provided after Lens execution.
      • lensExecutionRecord (Input) - GlideRecord of the Lens execution record.

      Wait for processed response

      Option to wait for ServiceNow AI Lens to display the output of post-processing on the Preview window. If enabled, it waits for the post processing output. Else, it doesn't wait for post processing output but post processing continues in the background.

      Max wait time (seconds)

      The maximum time ServiceNow AI Lens waits to display the output of post-processing. If the output doesn't appear within this duration, the session times out while the post-processing continues in the background until completion.

      Attach Captured Images To Record Option to attach the captured images to the record that is auto-filled using ServiceNow AI Lens.

      This option is enabled by default.

    7. To assign users or groups or roles to the Lens action, under the Assigned Users and Groups or Roles heading, select New, and then use any one of the following methods.
      MethodSteps
      Assign one or more roles to the Lens action Select Enable Roles and perform the following steps.
      1. Select the Unlock Roles (Roles Unlock icon.) icon.
      2. Select the Look up icon (Lookup Roles icon.) and then select a role.

        Repeat the step to add more roles.

      3. Select the Lock Roles icon (Lock Roles icon.).
      Assign one or more users to the Lens action
      1. To assign yourself, select the Add Me icon (Add Me icon.).
      2. To assign one or more users, select the Unlock Users (Roles Lock icon.) icon.
      3. Select the Look up icon (Lookup Roles icon.) and then select a user.
      4. Repeat the step to add more users.

      5. Select the Lock Users icon (Lock Roles icon.).
      Assign one or more groups to the Lens action
      1. Select the Unlock Groups (Groups Unlock icon.) icon.
      2. Select the Look up icon (Lookup Groups icon.) and then select a group.

        Repeat the step to add more groups.

      3. Select the Lock Groups icon (Lock Roles icon.).
      You can assign any one of the following combinations to the Lens action:
      • Assign roles to the Lens action.
      • Assign yourself and one or more groups to the Lens action.
      • Assign one or more users and groups to the Lens action
    8. Select Submit.
      The users or groups, or roles are assigned to the Lens action.
      Abbildung : 1. Users, groups, or roles assigned to Lens action
      Users, groups, or roles assigned to Lens action
    9. Select Update.
    10. Wahlweise: Update the assignment of users or groups or roles to the Lens action.
      Assignment typeSteps
      Roles
      1. Under the heading Assigned Users and Groups or Roles, select the role.
      2. To remove a role, select a role and then select (Remove role icon.)
      3. Assign one or more new roles. For more information, see servicenow-lens-actions.html#create-sn-lens-recipe__assign-roles-to-lens-action
      Users
      1. Under the heading Assigned Users and Groups or Roles, select the user.
      2. To remove a user, select a user and then select (Remove role icon.)
      3. Assign one or more new users. For more information, see servicenow-lens-actions.html#create-sn-lens-recipe__assign-users-to-lens-action
      Groups
      1. Under the heading Assigned Users and Groups or Roles, select the group.
      2. To remove a group, select a group and then select (Remove role icon.)
      3. Assign one or more new groups. For more information, see servicenow-lens-actions.html#create-sn-lens-recipe__assign-groups-to-lens-action
    11. Select Activate for activating the Lens action.
      The Lens action will be available on the ServiceNow AI Lens desktop application landing page.

    Example: Scan documents to auto-fill the Insurance Request form

    Enable customers to scan documents related to car accident on their desktop to auto-fill the Insurance Request form on the ServiceNow instance.

    Vorbereitungen

    Role required: lens_admin

    Warum und wann dieser Vorgang ausgeführt wird

    You can define in the Lens action that ServiceNow AI Lens must be triggered from the desktop to auto-fill the Insurance Request form. Lens action includes the fields that must be updated with the extracted data.

    Example Lens action record for auto-filling Insurance request form.

    Prozedur

    1. Navigate to All > ServiceNow Lens > Lens Actions.
    2. In the Name field, enter Auto-fill Insurance Request from desktop.
    3. In the Description field, enter Lens action for Boxeo Insurance to auto-fill the Insurance Request form when Lens is triggered from Desktop.
    4. From the Trigger From option, select Desktop.
    5. In the form header, right-click and select Save.
    6. From the Trigger For option, select Form.
    7. In the Table field, select the Insurance Request table.
    8. In the Request Context field, select Supported Fields to provide context.
    9. From the Fields field, move fields to the Selected list.
      policy_number, location_of_incident, policy_holder_name, vehicle_number, policy_state, policy_checks_failed, policy_checks_passed, incident_date_time, damage_description, claim_type, claim_evaluation_percentage
    10. In the Default Additional Directions field, enter the following directions for the Now Assist.
      1. Incident Date : If available, extract the date from pictures uploaded.
      2. Personal Information:
      	○ Names: Generate name from images or documents attached. If not present do not hallucinate.
      3. Location:
      	○ If a vehicle number is visible, extract the corresponding city or state from images. If not found in images based on the vehicle number extract U.S city/state and use it as the location.
      	○ If no vehicle number is visible, leave the field blank.
      4. Vehicle Number:
      	○ If present, use the visible vehicle number.
      	○ If not present, extract vehicle number from images like driving license. If not present, leave the field empty.
      5. Policy Checks:
      	○ Refer to the policy checks document for validation.  
      	○ List only passed checks in policyChecksPassed as an HTML table with columns: Check Name, Status, Remarks.
      	○ List only failed checks in policyChecksFailed as an HTML table with columns: Check Name, Status, Remarks. If a document/image is not found for a check then add it to the policyChecksFailed.
      	○ No validation should be skipped. Consider all rules under each policy section and add them into policyChecksPassed or policyChecksFailed based on they status whether they are passed or failed.
      6. Claim Evaluation:
      	○ Calculate the claimEvaluationPercentage using the formula:
      (Number of Passed Checks / Total Number of Checks) * 100
      7. Policy State:
      	○ "Valid" – if Claim Evaluation is 100,
      	○ "Needs More Information" – if Claim Evaluation is greater than 50 and less than 100,
      	○ "Failed" – if Claim Evaluation is less than or equal to 50.
      8. Ensure the final output with all the above fields accurately filled.
    11. Add users or groups who can use this Lens action.
      1. In the Assigned Users and Groups related list, select New.
      2. Select the required users or group of users that have the lens_user role.
        Only the assigned users or group of users can leverage the Lens action during Lens execution.
      3. Select Submit.
    12. Select Update.
    13. Select Activate for activating the Lens action.

    Example: Extract structured data from vendor agreements

    Enable compliance analysts to digitize and review several vendor agreements. Instead of manually entering details, they can launch ServiceNow AI Lens directly from the desktop, scan agreements, and adjust extracted values in the preview window before saving.

    Vorbereitungen

    Role required: lens_admin

    Warum und wann dieser Vorgang ausgeführt wird

    You can define in the Lens action that ServiceNow AI Lens must be triggered from the desktop to scan the documents saved on the user system. With the post processing option, you can edit the extracted information in the preview window before saving and trigger post processing to create related list records.

    Prozedur

    1. Navigate to All > ServiceNow Lens > Lens Actions.
    2. In the Name field, enter Extract data from vendor agreements.
    3. In the Description field, enter Digitize and review several vendor agreements.
    4. From the Trigger From option, select Desktop.
    5. In the form header, right-click and select Save.
    6. From the Trigger For option, select Others.
    7. In the Request Context field, select Advanced.
    8. In the Pre Processing Script field, enter the script to generate custom schema object for providing enhanced context.
      Here is the example of returned custom schema object:
      schemaObj =  {
        "schemaPayload": {
          "type": "json_schema",
          "json_schema": {
            "name": "schema_extraction",
            "schema": {
              "type": "object",
              "properties": {
                "vendorName": {
                  "type": "string",
                  "label": "Vendor Name"            
                },
                "contractTitle": {
                  "type": "string",
                  "label": "Contract Title"
                },
                "contractReferenceNumber": {
                  "type": "string",
                  "label": "Contract Reference Number"
                },
                "contractStartDate": {
                  "type": "string",            
                  "label": "Contract Start Date"
                },
                "contractEndDate": {
                  "type": "string",
                  "label": "Contract End Date"
                },
                "renewalTerminationClauses": {
                  "type": "string",
                  "label": "Renewal / Termination Clauses"
                }
              },
              "required": [
                "vendorName",
                "contractTitle",
                "contractReferenceNumber",
                "contractStartDate",
                "contractEndDate"
              ],
              "additionalProperties": false
            }
          }
        },
        "fieldLabels": ["vendorName", "contractTitle", "contractReferenceNumber", "contractStartDate", "contractEndDate"]  //Optional key
      }
    9. In the Default Additional Directions field, enter directions for the Now Assist, such as Leave the fields empty if you do not find the relevant information. Do not hallucinate. Enter the date in the DD-MM-YYYY.
    10. Select the Enable Post Processing option.
    11. In the Post Processing Script field, enter the script to provide the post processing logic for the Lens response after the Lens execution is complete.
      You can provide a post processing logic to pass the data extracted to a subflow for creating related list records.
    12. Wahlweise: Select the Wait for processed response field to enable the ServiceNow AI Lens to wait for ServiceNow AI Lens to display the output of post-processing on the Preview window.
      If enabled, it waits for the post processing output. Else, it doesn't wait for post processing output but post processing continues in the background.
    13. Wahlweise: In the Max wait time (seconds) field, specify the maximum time ServiceNow AI Lens waits to display the output of post-processing.
      Hinweis:
      If the output doesn't appear within that duration, the session times out while the post-processing continues in the background until completion.
    14. Add users or groups who can use this Lens action.
      1. In the Assigned Users and Groups related list, select New.
      2. Select the required users or group of users that have the lens_user role.
        Only the assigned users or group of users can leverage the Lens action during Lens execution.
      3. Select Submit.
    15. Select Update.
    16. Select Activate for activating the Lens action.

    Example: Auto-fill user records on a user table

    Enable service agents to create user records by extracting specific information from identity documents using ServiceNow AI Lens, directly from the ServiceNow instance.

    Vorbereitungen

    Role required: lens_admin

    Warum und wann dieser Vorgang ausgeführt wird

    A service agent must onboard multiple users by scanning their official ID cards (for example, government-issued ID). Instead of manually entering each user's details, the agents can trigger ServiceNow AI Lens from the instance to automate data extraction and auto-fill specific fields defined in the Lens action record.

    You can define in the Lens action that ServiceNow AI Lens must be triggered from the instance to create user records and provide default directions.

    Prozedur

    1. Navigate to All > ServiceNow Lens > Lens Actions.
    2. Select New.
    3. In the Name field, enter Auto-fill the user records.
    4. In the Description field, enter Lens action to auto-create the user records on the ServiceNow instance.
    5. From the Trigger From option, select Instance.
    6. In the form header, right-click and select Save.
    7. Confirm that the Form option is selected in the Trigger For field.
      The Form option is selected by default.
    8. In the Table field, select the User [sys_user] table.
    9. Confirm that Supported Fields is selected in the Request Context field.
      The Supported Fields value is selected by default, and it provides context.
    10. From the Fields field, move the fields to the Selected list.
      userID, first_name, last_name, title, and date_of_birth
    11. In the Default Additional Directions field, enter User ID must always be in lower case and uses the firstname.lastname format. Enter Date of birth in the dd-mm-yyyy format.
    12. Add users or groups who can use this Lens action.
      1. In the Assigned Users and Groups related list, select New.
      2. Select the required users or group of users that have the lens_user role.
        Only the assigned users or group of users can leverage the Lens action during Lens execution.
      3. Select Submit.
    13. Select Update.
    14. Select Activate for activating the Lens action.

    Auto-map Excel sheet column headers with ServiceNow table columns

    Use ServiceNow AI Lens to map the column headers of an Excel sheet that you specify with ServiceNow® table columns and then insert the Excel sheet data into the table.

    Vorbereitungen

    Role required: lens_user

    Ensure that the Lens action for this purpose is already defined. To view the steps to define a Lens action, see Define a Lens action. Ensure that the values in the Lens action form are exactly as specified in the following table.
    Tabelle : 3. Lens action Excel mapping configuration options
    Field Option you must select
    Trigger From Desktop
    Trigger For Excel Mapping
    Table Name of the table with which the Lens action will auto-map the Excel sheet column headers.
    Request context Supported Fields
    Fields Columns of the table
    Tipp:
    A preconfigured Lens action that is designed to auto-map Excel sheet column headers with table columns is available by default on your instance. The name of the Lens action is Import Excel Sheet data to custom table. To use the Lens action, create a copy of this Lens action, and customize to create your own Lens action for this purpose.

    Prozedur

    1. From your system, launch the ServiceNow AI Lens desktop application.
    2. On the login page, in the Instance URL field, enter the ServiceNow instance URL.
      For example, https://<instance name>.service-now.com.
    3. Select Proceed.
    4. Log in to your ServiceNow account by entering your username and password.
    5. Wahlweise: On the onboarding journey widget, complete the onboarding and select Got it.
      Onboarding journey widget with three pages to show you the highlights of the application.

      If you launch the ServiceNow AI Lens for the first time, the onboarding journey widget appears. You can select Don't show me again to hide the widget the next time you launch ServiceNow AI Lens.

    6. Select the Lens action that you have defined for Excel mapping.
      Excel mapping Lens action selected.
      The Proceed with Lens button is disabled.
      Hinweis:
      The Proceed with Lens button is disabled because to auto-map Excel sheet column headers with the table columns, ServiceNow AI Lens requires you to only attach an Excel sheet.
    7. Attach an Excel sheet by selecting Upload and then perform any one of the following file upload methods on the Upload file window.
      Abbildung : 2. File upload window
      Excel file upload window.
      File upload methodFile upload procedure
      Add file
      1. Select +Add file,
      2. Navigate to the location on your system and select the Excel sheet that you want to upload.
        Hinweis:
        • You can upload only one Excel sheet.
        • Tipp:
          To remove an Excel sheet that you attached, select the Remove file icon (Remove file).
        • The data only in the first worksheet of the Excel sheet will be analyzed.
      Drag and drop files
      1. Navigate to the location on your system and select the Excel sheet that you want to upload.
      2. Drag the selected Excel sheet to the Drag and drop section (Drag and drop section.), and release the pointer to drop them.
        Hinweis:
        • You can drag and drop only one Excel sheet.
        • Tipp:
          To remove an Excel sheet that you've attached, select the Remove file icon (Remove file).
        • The data only in the first worksheet of the Excel sheet will be analyzed.
    8. Select Next.
    9. Select Analyze.
      Analyze button.
      ServiceNow AI Lens auto-maps the column headers of the attached Excel sheet and the table columns.

      Lens Excel and table column mapping.

      Tipp:
      You can change the mapping by selecting one or more different table columns under the Imported as field heading.
    10. Select Submit.
      The Excel sheet data is inserted into the table.