> 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

Describes how to add ServiceNow-based approvals for a Pipeline.

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.

#### ServiceNow approval stages and 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.

  ![ServiceNow Approval stage](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-96531cff06a53f8897fd73a9d310aa947e554a96%2Fservice-now-approvals-00.png?alt=media)

#### 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.

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

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

![Add Stage in the pipeline](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-5717142fce8f4eb203be584f2070e2a0c2680bb2%2Fservice-now-approvals-01.png?alt=media)

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

![Approval selected as the stage type](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-f9183ab6962bcd30d4819bc77bcc505eda33d108%2Fservice-now-approvals-02.png?alt=media)

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.

![ServiceNow Approval step settings](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-1f1445e523002352a48fb39978fd0f812340b5cd%2Fservice-now-approvals-03.png?alt=media)

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

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` is 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](https://developer.harness.io/docs/platform/connectors/ticketing-systems/connect-to-service-now/) 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.

#### Set ServiceNow approval criteria

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.

![ServiceNow approval criteria](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-2d09c1c4ccac51d2551766c7f0fe85b17ff13e41%2Fservice-now-approvals-04.png?alt=media)

Whether the Pipeline/stage stops executing depends on the stage or step [Failure Strategy](https://developer.harness.io/docs/platform/pipelines/failure-handling/define-a-failure-strategy-on-stages-and-steps). 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: ![State in Resolved, Closed, or Cancelled](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-bfe6f08196f5ba9dc13819dcbe18301b34b0de66%2Fservice-now-approvals-08.png?alt=media)
* The condition for the `State` field to not be in either `New`, `In Progress`, or `On Hold` can be specified as: ![State not in New, In Progress, or On Hold](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-c0578821ce2af8c78c651343cf8582467829aa99%2Fservice-now-approvals-09.png?alt=media)
* The condition for the `State` field to be in `Resolved`, `Closed`, or `Cancelled` without fixed `Ticket Type` can be specified as: ![State in Resolved, Closed, or Cancelled with no fixed Ticket Type](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-1eb42145e36393c67a89dff964d999d5069413e6%2Fservice-now-approvals-10.png?alt=media)

{% 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**.

#### Set ServiceNow rejection criteria

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**.

#### 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**.

![Approval change window start and end](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-2f8963947fbe9a09e16ef15ef50eb54e41f2f5a2%2Fservice-now-approvals-05.png?alt=media)

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

#### ServiceNow advanced settings

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

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

#### Apply and test the ServiceNow approval

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:

![ServiceNow Approval step showing approval and rejection criteria during execution](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-dbe092b3b76ca9ada83fd580e512231aa13baaef%2Fservice-now-approvals-06.png?alt=media)

#### ServiceNow ticket expressions

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.**

![JEXL expression checking that the ticket state is New](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-5b2c15755d64c14d7c76a59cdd5b422b5b05a348%2Fservice-now-approvals-07.png?alt=media)

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

#### Refresh ServiceNow status during execution

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 re-evaluates the condition and proceeds 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** provides outputs that reference 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>`

![ServiceNow approval step output variables in the execution logs](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-597acb7657f72a736588239b1028a198c93223c4%2Fsnow-output-logs.png?alt=media)

#### 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 show the approval criteria on which the step was approved and the evaluating condition.\
  ![Logs for an approved ServiceNow Approval step](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-59588bda3bdfc8f6ad6b78d07b9b5faf686dd853%2Fsnow-approval-logs.png?alt=media)
* **Log example for a rejected step**:\
  The logs show the rejection criteria on which the step was rejected and the evaluating condition.\
  ![Logs for a rejected ServiceNow Approval step](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-5e3e4c5ed1d573c793490b2042a4a6eb1c34791f%2Fsnow-rejection-logs.png?alt=media)
* **Log example for using JEXL expression in approval criteria**:\
  The logs show the JEXL expression on which the step is approved or rejected and how the condition is evaluated.\
  ![Logs for a JEXL expression in ServiceNow approval criteria](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-199c75687b0c3b02150bd31868686000d61dc030%2Fsnow-approval-jexl-expression.png?alt=media)

#### 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).

#### ServiceNow notes

* 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).

{% @harness-feedback/feedback module="harness-ai" pagePath="harness-ai/use-harness-platform/approvals/service-now-approvals" %}
