---
sourceDocument: Australia Enable AI
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/pt-BR/intelligent-experiences

 Release :

    - australia

ft:locale :

    - pt-BR

ft:publication_title :

    - Australia Enable AI

ft:clusterId :

    - platai

bundleId :

    - platai

workflow :

    - Platform


---

# Script include - AILensActionService

# Script include - AILensActionService {#ariaid-title1}

* Versão de lançamento: Australia
* 
* Atualizado 12 de mar. de 2026
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 2 min. de leitura

Use the AILensActionService script include together with Lens actions to leverage ServiceNow AI Lens as a service for extracting information from the provided images and getting answers to your questions.

This script include is part of the ServiceNow AI Lens (sn_ai_lens) store application and is located within the `sn_app_lens_core` scope.  
This script include provides methods that enable the following:

* Calls Lens as a back-end service
* Analyzes and comprehends data from provided images
* Gets response from Now Assist as per provided directions
* Does not require ServiceNow AI Lens desktop app
{#ai-lens-action-service-api__ul_e3z_hwt_lgc}

## AILensActionService - AILensActionService() {#ariaid-title2}

Creates an AILensActionService instance.
{#ai-lens-action-const__table_hvj_vxt_lgc__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Tabela 1. Parameters]

{#ai-lens-action-const__table_hvj_vxt_lgc}  
The following example shows how to initialize AILensActionService.

    var lensService = new sn_app_lens_core. AILensActionService()

## AILensActionService - invokeLens(String lensActionId, String\[\] attachmentIds, String userPrompt, Object\[\] imageArr, Object inputJSON) {#ariaid-title3}

Invokes ServiceNow AI Lens as a service.
{#ailensactionservice-invokelens__table_v4d_qzt_lgc__entry__3}

| Name | Type | Description |
|-|-|-|
| lensActionId | String | Sys_id of the Lens Actions record created for your use case, or you can select the out-of-the-box option that fits your requirements. Example: 842bfc8e37066210b97528c734924baf This parameter is mandatory. |
| attachmentIds | String\[\] | Array of sys_ids for existing image attachments. Example: `["0067e66f93f022108319f9ed1dba108b", "0000e8a42c9a7110f877137af4eab4b5"]` You must pass either `attachmentIds` or `imageArr` parameter. |
| userPrompt | String | An instruction or question for Now Assist to answer after analyzing the contents of the attachments. Example: <kbd class="ph userinput">Analyze this production issue and create an incident ticket</kbd> |
| imageArr | Object\[\] | Array of objects containing name of the screenshot and base64 encoded image data. Example: [ { name: "screenshot1.png", data: "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==" }, { name: "screenshot2.png", data: "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9Qz0AEYAJMgkU1f5kAAAAASUVORK5CYII=" } ]; You must pass either `attachmentIds` or `imageArr` parameter. |
| inputJSON | Object | Additional JSON input parameters that you want to pass in the pre-processing script of the Lens action. Example: { "type" : "object", "properties" : { "short_description" : { "type" : "string", "label" : "Short description" }, "description" : { "type" : "string", "label" : "Description" }, }, "required" : [ "short_description", "comments" ], } |
| additionalContext | Object | An optional parameter that you can use to pass any extra key--value information from the client to the server during the Lens action call. Example {IsFileUploadEnabled: true} |
[Tabela 2. Parameters]

{#ailensactionservice-invokelens__table_v4d_qzt_lgc} {#ailensactionservice-invokelens__table_w4d_qzt_lgc__entry__2}

| Type | Description |
|-|-|
| \<object\> | Returned success object { "status": "success", "lensResponse": "{\"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.\" }" } |
| error | Returned error object { "status": "error", "error": { "errorType": "Execution Error", "message": "Detailed error message here" } } |
[Tabela 3. Returns]

{#ailensactionservice-invokelens__table_w4d_qzt_lgc}  
This example shows how to call Lens service from a script block.

    var lensActionId = "cd6570cdf36a2210b9751f09f6968c42";
    var attachmentIds = ["3fe930093b626210aba1fadc73e45a38", "0000e8a42c9a7110f877137af4eab4b5"];
    var userPrompt = "Analyze this production issue and create an incident ticket";
    var imageArr = [
        {
            name: "screenshot1.png",
            data: "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg=="
        },
        {
            name: "screenshot2.png",
            data: "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9Qz0AEYAJMgkU1f5kAAAAASUVORK5CYII="
        }
    ];
    var inputJSON = {
          "type" : "object",
          "properties" : {
            "short_description" : {
              "type" : "string",
              "label" : "Short description"
            },
            "description" : {
              "type" : "string",
              "label" : "Description"
            },
          },
          "required" : [ "short_description", "comments" ],
       }
     // Call the method
    var result = new sn_app_lens_core. AILensActionService().invokeLens(lensActionId, attachmentIds, userPrompt, imageArr, inputJSON);
     
    // Handle the response
    if (result.status === 'success') {
        var response = JSON.parse(result.lensResponse);
        gs.info("AI Lens Analysis Complete:");
        gs.info("Title:", response.short_description);
        gs.info("Description:", response.description);
    } else {
        gs.error("Error occurred:", result.error.message);
    }


