> For the complete documentation index, see [llms.txt](https://developer.harness.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.harness.io/harness-platform/use-harness-platform/approvals/service-now-approvals.md).

# Adding ServiceNow approval steps and stages

You can use ServiceNow tickets to approve or reject a Pipeline or stage at any point in its execution.

During deployment, a ServiceNow ticket's fields are evaluated according to the criteria you define, and its approval/rejection determines if the Pipeline or stage may proceed.

Approvals can be added as stages or in-between stage steps to prevent stage execution from proceeding without approval.

For example, in a [Kubernetes Blue Green Deployment](/continuous-delivery/use-continuous-delivery/deploy-services-on-different-platforms/kubernetes/kubernetes-executions/create-a-kubernetes-blue-green-deployment.md), you might want to add an approval step between the Stage Deployment step, where the new app version is deployed to the staging environment, and the Swap Primary with Stage step, where production traffic is routed to the pods for the new version.

#### Before you begin <a href="#before-you-begin" id="before-you-begin"></a>

* [Connect to ServiceNow](/harness-platform/use-harness-platform/connectors/ticketing-systems/connect-to-service-now.md)

#### Review: ServiceNow Approval Stages vs Steps <a href="#review-servicenow-approval-stages-vs-steps" id="review-servicenow-approval-stages-vs-steps"></a>

You can use ServiceNow Approvals in two ways:

* **ServiceNow Approval step:** you can add a ServiceNow Approval step to any Pipeline or Approval stage.
* **ServiceNow** **Approval stage:** the ServiceNow Approval stage.

  ![](/spaces/y1JhZ4oKIppwY7d5AhPj/files/qb2d8qtpk0EZLAILAyhQ)

#### UTC Timezone Only <a href="#utc-timezone-only" id="utc-timezone-only"></a>

The ServiceNow API only allows date time and time values in the UTC timezone. Consequently, input for any datetime/time fields in Harness ServiceNow steps must be provided in UTC format irrespective of time zone settings in your ServiceNow account.

The timezone settings govern the display value of the settings not their actual value.

The display values in the Harness UI depend on ServiceNow timezone settings.

#### Step: Add an Approval Step <a href="#step-add-an-approval-step" id="step-add-an-approval-step"></a>

In your Pipeline, click **Add Stage**.

![](/spaces/y1JhZ4oKIppwY7d5AhPj/files/jAd9bpIn8l8TQ6uxiRLm)

Click **Approval**. The Stage settings appear.

![](/spaces/y1JhZ4oKIppwY7d5AhPj/files/ReibW46eyMKjK8CViuDy)

In **Name**, enter a name for your Stage and select **ServiceNow** as approval type. Click **Setup Stage**. The pipeline appears.

In the pipeline, click **ServiceNow Approval.** The **ServiceNow Approval** settings appear.

![](/spaces/y1JhZ4oKIppwY7d5AhPj/files/WfIAhX9vrJmcetc0OVlL)

In **Timeout**, enter how long you want Harness to try to complete the step before failing (and initiating the stage or step [Failure Strategy](/harness-platform/use-harness-platform/pipelines/failure-handling/define-a-failure-strategy-on-stages-and-steps.md)).

You can use `**w**` for week, `**d**` for day, `**h**` for hour, `**m**` for minutes, `**s**` for seconds and `**ms**` for milliseconds. For example, 1d for one day.

ServiceNow communication can take a few minutes. Do not use a brief timeout.

The maximum is 3w 3d 20h 30m. In **ServiceNow** **Connector,** create or select the [ServiceNow Connector](/harness-platform/use-harness-platform/connectors/ticketing-systems/connect-to-service-now.md) you want to use.

Select the ServiceNow **Ticket Type**. Use the same type as the ticket you created in the Workflow.

Enter the ServiceNow **Ticket Number**.

In **Retry Interval**, set how long the step should wait to fetch details again for calculating Approval or Rejection criteria.

#### Step 2: Set Approval Criteria <a href="#step-2-set-approval-criteria" id="step-2-set-approval-criteria"></a>

The **Approval Criteria** in the step determines if the Pipeline or stage is approved or rejected. Define the approval criteria using the ServiceNow status items.

![](/spaces/y1JhZ4oKIppwY7d5AhPj/files/w7AhbTgrj3Md4veMUCT7)

Whether the Pipeline/stage stops executing depends on the stage or step [Failure Strategy](/harness-platform/use-harness-platform/pipelines/failure-handling/define-a-failure-strategy-on-stages-and-steps.md).You can specify criteria using **Conditions** and/or **JEXL Expression**. If you use them in combination, they both must evaluate to `True` for the step to be successful.

In **Conditions**, you can use the ServiceNow ticket related fields to define approval criteria. Four supported operators are `=`, `!=`, `in`, and `not in`. For example,

* The condition for the `State` field to be in `Resolved`, `Closed`, or `Cancelled` can be specified as: ![](/spaces/y1JhZ4oKIppwY7d5AhPj/files/V6pepoP94fUJjOlwEkGz)
* The condition for the `State` field to not be in either `New`, `In Progress`, or `On Hold` can be specified as: ![](/spaces/y1JhZ4oKIppwY7d5AhPj/files/uAqLQ10pDgUOje4JWK6b)
* The condition for the `State` field to be in `Resolved`, `Closed`, or `Cancelled` without fixed `Ticket Type` can be specified as: ![](/spaces/y1JhZ4oKIppwY7d5AhPj/files/wsYo6mbliymkblSMCW2H)

{% hint style="info" %}
**IMPORTANT**

Multiple conditions with the same Jira field are not allowed. Such use cases can be solved using `in`, `not in` operators, or **JEXL Expression**.
{% endhint %}

In **JEXL Expression**, you can use [JEXL expressions](https://commons.apache.org/proper/commons-jexl/reference/syntax.html). You can use a JEXL expression if the field is set to **Fixed value** or **Expression**.

#### Option: Set Rejection Criteria <a href="#option-set-rejection-criteria" id="option-set-rejection-criteria"></a>

In **Optional Configuration**, in **Rejection Criteria**, you can define criteria for rejecting the approval. Define the rejected criteria using the ServiceNow status items.

If you add rejection criteria, it is used in addition to the settings in **Approval Criteria**.

#### Option: Approval Change Window <a href="#option-approval-change-window" id="option-approval-change-window"></a>

In **Approval Change Window**, use **Window Start** and **Window End** values to specify the window in which Harness will proceed with the deployment. Once this step is approved, Harness proceeds with deployment if the current time is within this window. The values that appear depend on the type selected in **Ticket Type**.

![](/spaces/y1JhZ4oKIppwY7d5AhPj/files/wwUKs06RKLgVZ82szb8D)

The start and end times use the time zone set in the ServiceNow account selected in the ServiceNow Connector.

#### Option: Advanced Settings <a href="#option-advanced-settings" id="option-advanced-settings"></a>

In **Advanced**, you can use the following options:

* [Delegate Selector](/harness-platform/use-harness-platform/delegates/delegate/manage-delegates/select-delegates-with-selectors.md)
* [Step Skip Condition Settings](/harness-platform/use-harness-platform/pipelines/step-skip-condition-settings.md)
* [Step Failure Strategy Settings](/harness-platform/use-harness-platform/pipelines/failure-handling/define-a-failure-strategy-on-stages-and-steps.md)

#### Step 3: Apply and Test <a href="#step-3-apply-and-test" id="step-3-apply-and-test"></a>

Click **Apply Changes**. The ServiceNow approval step is added to the stage.

Run the Pipeline.

When the ServiceNow Approval step is reached, you can see its approval and rejection criteria:

![](/spaces/y1JhZ4oKIppwY7d5AhPj/files/uK4ib939aXeZWrM6hfQC)

#### Review: Issue expressions <a href="#review-issue-expressions" id="review-issue-expressions"></a>

You can use `<+ticket>` to refer to the value in the **JEXL Expression** setting.

For example, `<+ticket.state.displayValue> == "New"` in the Approval Criteria, **JEXL Expression** checks to see if the status of the ticket is **New.**

![](/spaces/y1JhZ4oKIppwY7d5AhPj/files/z0sqCkljTE1vBNZStDw1)

`state` is a ticket field. You can use any ticket field.

#### Manual Refresh During Execution <a href="#manual-refresh-during-execution" id="manual-refresh-during-execution"></a>

You can do a **manual status refresh** in the Pipeline Studio Execution view.

When the step is waiting for a response from ServiceNow, you can use the **Refresh** button to immediately fetch the **latest status of the approval ticket** instead of waiting for the polling interval.

Use the refresh option when:

* The approval condition in ServiceNow was updated after the step began execution.
* You need quicker response handling for fast-track approvals such as incident mitigations or emergency changes.

To use the refresh button:

* Execute a pipeline with a ServiceNow Approval step.
* In the Pipeline Studio Execution view, locate the approval step.
* If the step is in a waiting state, click the Refresh button.
* The step will re-evaluate the condition and proceed if the criteria are met.

#### Output <a href="#output" id="output"></a>

Regardless of whether the step is approved or rejected, the **ServiceNow approval step** will provide outputs referencing the details of the step, such as:

* `ticketType`
* `ticketNumber`
* `Approval Criteria`
* `Rejection Criteria`
* `Conditions`
* `hasApprovalCriteriaMet`
* `hasRejectionCriteriaMet`

These outputs can be used as **output variables** and referenced in subsequent steps or stages.

Here are a few expression examples that can be used to fetch the output values:

* **ticketType**: `<+pipeline.stages.stage.spec.execution.steps.ServiceNowApproval_1.output.ticketType>`
* **ticketNumber**: `<+pipeline.stages.stage.spec.execution.steps.ServiceNowApproval_1.output.ticketNumber>`
* **approvalCriteria**: `<+pipeline.stages.stage.spec.execution.steps.ServiceNowApproval_1.output.approvalCriteria.type>`
* **rejectionCriteria**: `<+pipeline.stages.stage.spec.execution.steps.ServiceNowApproval_1.output.rejectionCriteria.type>`

<figure><img src="/spaces/y1JhZ4oKIppwY7d5AhPj/files/AVnjZxDsaWcYyps1IM8N" alt=""><figcaption><p>Click to view full size image</p></figcaption></figure>

#### Logs <a href="#logs" id="logs"></a>

You can also view detailed logs that describe why the validation **failed** or **succeeded** in the **ServiceNow approval step**.

Here are examples of logs for different scenarios:

* **Log example for an approved step**:\
  The logs will show the approval criteria on which the step was approved and the evaluating condition.\
  ![](/spaces/y1JhZ4oKIppwY7d5AhPj/files/ZoxT7BcYeRkmuW5JmLpW)
* **Log example for a rejected step**:\
  The logs will show the rejection criteria on which the step was rejected and the evaluating condition.\
  ![](/spaces/y1JhZ4oKIppwY7d5AhPj/files/GcnL3ADVAjJrkzrKhuqw)
* **Log example for using JEXL expression in approval criteria**:\
  The logs will show the JEXL expression on which the step will be approved or rejected and how the condition is evaluated.\
  ![](/spaces/y1JhZ4oKIppwY7d5AhPj/files/xWdYINJ9ZRhGfUmNuIwq)

### Custom table support <a href="#custom-table-support" id="custom-table-support"></a>

For details, go to **Custom table support** in [Create ServiceNow tickets in CD stages](/continuous-delivery/use-continuous-delivery/cd-building-blocks/cd-steps/ticketing-systems/create-service-now-tickets-in-cd-stages.md#custom-table-support).

#### Notes <a href="#notes" id="notes"></a>

* For more information about approval log limitations, go to [Deployment logs and limitations](/continuous-delivery/use-continuous-delivery/manage-deployments/deployment-logs-and-limitations.md).

### See also <a href="#see-also" id="see-also"></a>

* [Using Manual Harness Approval Stages](/harness-platform/use-harness-platform/approvals/adding-harness-approval-stages.md)
* [Using Manual Harness Approval Steps in CD Stages](/continuous-delivery/use-continuous-delivery/cd-building-blocks/cd-steps/approvals/using-harness-approval-steps-in-cd-stages.md)
