---
title: Create a static NRQL condition
source: https://docs.newrelic.com/docs/workflow-automation/setup-and-configure/actions-catalog/newrelic/alerts/newrelic-alerts-create-static-nrql-condition
---

The action identifier is `newrelic.alerts.createStaticNrqlCondition`.

Creates a new static NRQL alert condition under an alert policy. A static NRQL condition evaluates a NRQL query on a fixed schedule and opens a violation when the result crosses a fixed threshold.

At least one of `terms` or `expiration` (with `openViolationOnExpiration: true`) must be provided. Omitting both fails NerdGraph validation.

## Inputs

The following table describes all available input fields for this action.

| Input                         | Type    | Description                                                                                                                                                                                                                                                                                                                                                                                                    | Example                                                                                                                    |
| ----------------------------- | ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------- |
| **accountId**                 | Int     | **Required.** The New Relic account in which to create the condition.                                                                                                                                                                                                                                                                                                                                          | `123456`                                                                                                                   |
| **policyId**                  | String  | **Required.** The ID of the alert policy to attach this condition to.                                                                                                                                                                                                                                                                                                                                          | `"2000002"`                                                                                                                |
| **name**                      | String  | **Required.** The name of the condition.                                                                                                                                                                                                                                                                                                                                                                       | `"High error rate"`                                                                                                        |
| **nrqlQuery**                 | String  | **Required.** The NRQL query to evaluate.                                                                                                                                                                                                                                                                                                                                                                      | `"SELECT count(*) FROM TransactionError WHERE appName = 'MyApp'"`                                                          |
| **enabled**                   | Boolean | **Required.** Whether the condition is active.                                                                                                                                                                                                                                                                                                                                                                 | `true`                                                                                                                     |
| **terms**                     | List    | **Conditionally required.** The condition's thresholds. Required unless `expiration` is provided with `openViolationOnExpiration: true`. Each entry requires: `priority` (`CRITICAL` or `WARNING`), `operator` (`ABOVE`, `ABOVE_OR_EQUALS`, `BELOW`, `BELOW_OR_EQUALS`, `EQUALS`, or `NOT_EQUALS`), `threshold` (float), `thresholdDuration` (seconds), and `thresholdOccurrences` (`ALL` or `AT_LEAST_ONCE`). | `[{"priority": "CRITICAL", "operator": "ABOVE", "threshold": 5, "thresholdDuration": 300, "thresholdOccurrences": "ALL"}]` |
| **nrqlDataAccountId**         | Int     | **Optional.** Account to run the NRQL query against if different from `accountId`.                                                                                                                                                                                                                                                                                                                             | `123456`                                                                                                                   |
| **description**               | String  | **Optional.** Free-text description of the condition.                                                                                                                                                                                                                                                                                                                                                          | `"Alerts when the error rate exceeds the threshold."`                                                                      |
| **runbookUrl**                | String  | **Optional.** URL of a runbook to link from the condition.                                                                                                                                                                                                                                                                                                                                                     | `"https://runbooks.example.com/high-error-rate"`                                                                           |
| **titleTemplate**             | String  | **Optional.** Handlebars-style template for the violation title.                                                                                                                                                                                                                                                                                                                                               | `"{{ conditionName }} on {{ entity.name }}"`                                                                               |
| **violationTimeLimitSeconds** | Int     | **Optional.** Force-closes an open violation after this many seconds.                                                                                                                                                                                                                                                                                                                                          | `86400`                                                                                                                    |
| **signal**                    | Map     | **Optional.** Advanced signal and streaming settings: `aggregationWindow`, `aggregationMethod` (`EVENT_FLOW`, `EVENT_TIMER`, or `CADENCE`), `aggregationDelay`, `aggregationTimer`, `slideBy`, `evaluationDelay`, `fillOption` (`NONE`, `LAST_VALUE`, or `STATIC`), `fillValue`, `pollingFrequency`.                                                                                                           | `{"aggregationWindow": 60, "aggregationMethod": "EVENT_FLOW", "aggregationDelay": 120}`                                    |
| **expiration**                | Map     | **Optional.** Loss-of-signal settings: `closeViolationsOnExpiration`, `expirationDuration` (seconds), `openViolationOnExpiration`, `ignoreOnExpectedTermination`.                                                                                                                                                                                                                                              | `{"closeViolationsOnExpiration": true, "expirationDuration": 300, "openViolationOnExpiration": false}`                     |
| **selectors**                 | List    | **Optional.** JQ selectors to extract values from the response.                                                                                                                                                                                                                                                                                                                                                | ```yaml selectors:   - name: conditionId     expression: ".data.alertsNrqlConditionStaticCreate.id" ```                    |

## Outputs

The following table describes all output fields returned by this action.

| Output           | Type    | Description                                                                                                                                                                                                                                                                                                                                                                                                      |
| ---------------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **success**      | Boolean | `true` when the step executed without error.                                                                                                                                                                                                                                                                                                                                                                     |
| **errorMessage** | String  | Error message on failure, including NerdGraph errors. `null` on success.                                                                                                                                                                                                                                                                                                                                         |
| **data**         | Map     | NerdGraph response. Use `selectors` to extract `id`, `name`, `enabled`, `policyId`, `entityGuid`, or `type` from `data`. ```json {   "data": {     "alertsNrqlConditionStaticCreate": {       "id": "7654321",       "name": "High error rate",       "enabled": true,       "policyId": "2000002",       "entityGuid": "MTE5MzMzNDd8TlIxfE5SUV9DT05EQVRJT058NzY1NDMyMQ",       "type": "STATIC"     }   } } ``` |

## Example

The following example creates a static NRQL condition and captures its ID for use in subsequent steps.

| Workflow example                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| ```yaml name: create_static_nrql_condition description: Create a static NRQL alert condition steps:   - name: createCondition     type: action     action: newrelic.alerts.createStaticNrqlCondition     version: 1     inputs:       accountId: ${{ .workflowInputs.accountId }}       policyId: ${{ .workflowInputs.policyId }}       name: "High error rate"       nrqlQuery: "SELECT count(*) FROM TransactionError WHERE appName = 'MyApp'"       enabled: true       terms:         - priority: "CRITICAL"           operator: "ABOVE"           threshold: 5           thresholdDuration: 300           thresholdOccurrences: "ALL"       selectors:         - name: conditionId           expression: ".data.alertsNrqlConditionStaticCreate.id"     next: end ``` |
