---
title: New Relic Lens actions
source: https://docs.newrelic.com/docs/workflow-automation/setup-and-configure/actions-catalog/newrelic/newrelic-lens
---

This page provides a reference for New Relic Lens actions available in the workflow automation actions catalog. These actions let you run ANSI SQL queries against data sources connected through New Relic Lens directly from a workflow step.

## Prerequisites

Before using New Relic Lens actions in workflow automation, ensure you have:

-   A New Relic account with appropriate permissions.
-   One or more data sources connected in New Relic Lens.
-   The necessary permissions for the New Relic Lens service.

**Query Lens**

Runs an ANSI SQL query against connected data sources through New Relic Lens.

### Inputs

The following inputs are available for this action.

| Input          | Optionality | Type        | Description                                                                                                                        | Example                                                                                                                                                                                                                                                                                                                                                                     |
| -------------- | ----------- | ----------- | ---------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **query**      | Required    | String      | The ANSI SQL statement to execute via Lens. Supports cross-source joins across connected data sources.                             |                                                                                                                                                                                                                                                                                                                                                                             |
| **accountIds** | Optional    | List of int | The target accounts for query execution. If you don't provide this field, the query runs against the workflow's execution account. |                                                                                                                                                                                                                                                                                                                                                                             |
| **format**     | Optional    | Enum        | The output format for results. Accepts `JSON`, `CSV`, `PSV`, or `TSV`. Defaults to `JSON`.                                         |                                                                                                                                                                                                                                                                                                                                                                             |
| **selectors**  | Optional    | List        | The selectors to get only the specified parameters as output.                                                                      | ```yaml steps:   - name: queryLens     type: action     action: newrelic.lens.query     version: 1     inputs:       accountIds: [12345]       query: >         SELECT appName,appId, count(*) as count FROM telemetry.Transaction         GROUP BY appName, appId LIMIT 1       selectors:         - name: resultsAsString           expression: '.results | tostring' ``` |

### Outputs

This action returns the following outputs.

| Output           | Type    | Description                                                                                                                                                                                                                    | Example                                                                                                                                                     |
| ---------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **results**      | List    | An array of objects containing the results of the query. See [Expressions property](https://docs.newrelic.com/docs/workflow-automation/workflow-automation-apis/definition-schema#expression-properties) for more information. |                                                                                                                                                             |
| **success**      | Boolean | Returns `true` if the action succeeded, `false` otherwise.                                                                                                                                                                     |                                                                                                                                                             |
| **errorMessage** | String  | Contains the failure reason if the action fails.                                                                                                                                                                               | ```json {   "success": true,   "results": [     { "appName": "workflow-service (production.us-exit-speed)", "appId": 2882375598, "count": 52688 }   ] } ``` |
