--- title: Define ServiceNow AI Lens behavior with Lens actions description: 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.Create a Lens action to define custom context, trigger options, and default instructions for the ServiceNow AI Lens execution.Enable customers to scan documents related to car accident on their desktop to auto-fill the Insurance Request form on the ServiceNow instance.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.Enable service agents to create user records by extracting specific information from identity documents using ServiceNow AI Lens, directly from the ServiceNow instance.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. locale: en-US canonical_url: https://www.servicenow.com/docs/r/australia/intelligent-experiences/servicenow-lens/servicenow-lens-actions.html release: australia product: ServiceNow Lens classification: servicenow-lens topic_type: concept last_updated: "2026-08-04" reading_time_minutes: 22 breadcrumb: [Configure, ServiceNow AI Lens, Enable AI experiences] --- # Define ServiceNow AI Lens behavior with Lens actions 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. - [Example: Scan documents to auto-fill the Insurance Request form](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/intelligent-experiences/servicenow-lens/servicenow-lens-actions.md) - [Example: Extract structured data from vendor agreements](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/intelligent-experiences/servicenow-lens/servicenow-lens-actions.md) - [Example: Auto-fill user records on a user table](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/intelligent-experiences/servicenow-lens/servicenow-lens-actions.md) - [Auto-map Excel sheet column headers with ServiceNow table columns](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/intelligent-experiences/servicenow-lens/servicenow-lens-actions.md) ## 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. ### Before you begin Role required: lens\_admin ### About this task Learn about the various Lens trigger options for ServiceNow AI Lens.
| 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](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/intelligent-experiences/servicenow-lens/default-prompt-system-property-lens.md). | 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.](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/intelligent-experiences/servicenow-lens/servicenow-lens-actions.md) | 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 |
| 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 [https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/intelligent-experiences/servicenow-lens/servicenow-lens-actions.md](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/intelligent-experiences/servicenow-lens/servicenow-lens-actions.md) 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](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/intelligent-experiences/servicenow-lens/field-types-supported.md).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 AI 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. |
| Method | Steps |
|---|---|
| **Assign one or more roles to the Lens action** | Select **Enable Roles** and perform the following steps.1. Select the Unlock Roles \(\[Omitted image "lens-lock-icon.png"\] Alt text: Roles Unlock icon.\) icon. 2. Select the Look up icon \[Omitted image "lens-magnify-icon.png"\] Alt text: and then select a role. Repeat the step to add more roles. 3. Select the Lock Roles icon \[Omitted image "lens-lock-roles-icon.png"\] Alt text:. |
| **Assign one or more users to the Lens action** | 1. To assign yourself, select the Add Me icon \[Omitted image "lens-add-me-icon.png"\] Alt text:. 2. To assign one or more users, select the Unlock Users \(\[Omitted image "lens-lock-icon.png"\] Alt text: Roles Lock icon.\) icon. 3. Select the Look up icon \[Omitted image "lens-magnify-icon.png"\] Alt text: and then select a user. 4. Repeat the step to add more users. 5. Select the Lock Users icon \[Omitted image "lens-lock-roles-icon.png"\] Alt text:. |
| **Assign one or more groups to the Lens action** | 1. Select the Unlock Groups \[Omitted image "lens-lock-icon.png"\] Alt text: icon. 2. Select the Look up icon \[Omitted image "lens-magnify-icon.png"\] Alt text: and then select a group. Repeat the step to add more groups. 3. Select the Lock Groups icon \[Omitted image "lens-lock-roles-icon.png"\] Alt text:. |
| Assignment type | Steps |
|---|---|
| **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 \(\[Omitted image "lens-file-attch-remove.png"\] Alt text: Remove role icon.\) 3. Assign one or more new roles. For more information, see [https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/intelligent-experiences/servicenow-lens/servicenow-lens-actions.md](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/intelligent-experiences/servicenow-lens/servicenow-lens-actions.md) |
| **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 \(\[Omitted image "lens-file-attch-remove.png"\] Alt text: Remove role icon.\) 3. Assign one or more new users. For more information, see [https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/intelligent-experiences/servicenow-lens/servicenow-lens-actions.md](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/intelligent-experiences/servicenow-lens/servicenow-lens-actions.md) |
| **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 \(\[Omitted image "lens-file-attch-remove.png"\] Alt text: Remove role icon.\) 3. Assign one or more new groups. For more information, see [https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/intelligent-experiences/servicenow-lens/servicenow-lens-actions.md](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/intelligent-experiences/servicenow-lens/servicenow-lens-actions.md) |
| File upload method | File 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. **Note:** - You can upload only one Excel sheet. - **Tip:** To remove an Excel sheet that you attached, select the Remove file icon \[Omitted image "lens-file-attch-remove.png"\] Alt text:. - 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 \(\[Omitted image "lens-drag-and-drop.png"\] Alt text: Drag and drop section.\), and release the pointer to drop them. **Note:** - You can drag and drop only one Excel sheet. - **Tip:** To remove an Excel sheet that you've attached, select the Remove file icon \[Omitted image "lens-file-attch-remove.png"\] Alt text:. - The data only in the first worksheet of the Excel sheet will be analyzed. |