> 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/continuous-delivery/use-continuous-delivery/cd-building-blocks/cd-steps/ticketing-systems/update-service-now-tickets-in-cd-stages.md).

# Update ServiceNow tickets in CD stages

Update ServiceNow tickets from Deploy and Approval stages in Continuous Delivery pipelines

{% hint style="info" %}
This feature is in Beta[^1] and requires enablement. [View all early access features.](/release-notes/features.md)

{% @harness-feature-flag-access/request-feature-flag-access module="continuous-delivery" pagePath="continuous-delivery/use-continuous-delivery/cd-building-blocks/cd-steps/ticketing-systems/update-service-now-tickets-in-cd-stages" featureFlags="%5B%7B%22name%22%3A%22Fetch%20ServiceNow%20field%20values%20for%20fixed%20ticket%20numbers%22%2C%22key%22%3A%22CDS\_SERVICENOW\_FETCH\_FIELDS%22%2C%22status%22%3A%22BETA%22%2C%22description%22%3A%22When%20the%20ticket%20number%20is%20a%20fixed%20value%2C%20Harness%20can%20fetch%20current%20field%20values%20from%20ServiceNow%20and%20show%20a%20refresh%20control%20when%20values%20change.%22%7D%5D" %}
{% endhint %}

This topic describes how to update ServiceNow tickets in Harness Deploy and Approval stages.

Harness provides the ability to update [ServiceNow change requests](https://docs.servicenow.com/bundle/rome-it-service-management/page/product/change-management/concept/c_ITILChangeManagement.html), [incident tickets](https://docs.servicenow.com/bundle/rome-it-service-management/page/product/incident-management/concept/c_IncidentManagement.html), [change tasks](https://docs.servicenow.com/bundle/rome-it-service-management/page/product/change-management/concept/change-types.html), and [problem type](https://docs.servicenow.com/bundle/rome-it-service-management/page/product/problem-management/concept/c_ProblemManagement.html) from your pipeline step using the **ServiceNow Update** step.

You can add the ServiceNow Update step to a Harness Deploy stage or an Approval stage and do the following:

* Automatically update change requests in ServiceNow to track updates to your build, test, and production environments by adding a **ServiceNow Update** step in your pipeline.
* Automatically assign tickets in ServiceNow to triage and resolve incidents quickly in case of pipeline failures.

***

## What you will learn from this topic

* How to [add a ServiceNow Update step](#add-a-servicenow-update-step) to a stage
* How to [update fields](#update-fields) and [use expressions in Ticket Number](#use-expressions-in-ticket-number)
* How to [apply from a template](#apply-from-template) and use [custom table support](#custom-table-support)

***

## Before you begin

The following prerequisites apply to the ServiceNow Update step:

* **ServiceNow connector**: Add a Harness ServiceNow connector before or during the Update ServiceNow step setup. Go to [Connect to ServiceNow](https://developer.harness.io/docs/platform/connectors/ticketing-systems/connect-to-service-now) to create one.
* **ServiceNow roles**: You need the `itil` role for end-to-end integration with Harness.
* **Harness app and template roles (templates only)**: To update tickets from templates, install the Integration for Harness Software Delivery Platform app and grant `x_harne_harness_ap.integration_user_role` to access templates. Go to [Required ServiceNow integration app for Harness templates](#required-servicenow-integration-app-for-harness-templates) to install the app.
* **Approvals (optional)**: Go to [Adding ServiceNow approval steps and stages](https://developer.harness.io/docs/platform/approvals/service-now-approvals) to gate pipelines with ServiceNow tickets.

{% hint style="warning" %}
**Provide datetime values in UTC**

The ServiceNow API only allows date time and time values in the UTC timezone. Consequently, input for any datetime or 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.
{% endhint %}

***

## Required ServiceNow integration app for Harness templates <a href="#required-servicenow-integration-app-for-harness-templates" id="required-servicenow-integration-app-for-harness-templates"></a>

The Integration for Harness Software Delivery Platform app is required to update ServiceNow tickets using Harness templates. You can install the latest version of the Integration for Harness Software Delivery Platform app in your ServiceNow instance from the [ServiceNow store](https://store.servicenow.com/sn_appstore_store.do#!/store/application/de154a1e1b75851044cbdb58b04bcb11/1.0.2?referer=%2Fstore%2Fsearch%3Flistingtype%3Dallintegrations%25253Bancillary_app%25253Bcertified_apps%25253Bcontent%25253Bindustry_solution%25253Boem%25253Butility%25253Btemplate%26q%3Dharness\&sl=sh).

Go to the [ServiceNow installation guide](https://store.servicenow.com/appStoreAttachments.do?sys_id=1fc1632b872f4dd0970e2178cebb35ba) to install the app.

***

## Add a ServiceNow Update step <a href="#add-a-servicenow-update-step" id="add-a-servicenow-update-step"></a>

Perform the following steps to add a ServiceNow Update step:

1. In a Harness Deploy or Approval stage, in **Execution**, select **Add Step**.
2. Select **ServiceNow Update**. The ServiceNow Update settings appear.
3. In **Name**, enter a name that describes the step.
4. In **Timeout**, enter how long you want Harness to try to update the ticket 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)).
5. In **ServiceNow Connector**, create or select the [ServiceNow connector](https://developer.harness.io/docs/platform/connectors/ticketing-systems/connect-to-service-now) to use.
6. In **Ticket Type**, select a ServiceNow ticket type from the list.

   ![ServiceNow Update step with Ticket Type selected](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-046a326367f23400033e3474b9251d2ada835a15%2Fcreate-service-now-tickets-in-cd-stages-07.png?alt=media)
7. In **Ticket Number**, enter the ServiceNow ticket number to update. You can enter fixed values, provide runtime input, or provide an expression for this field.

   ![Ticket Number field on the ServiceNow Update step](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-f40665ee4a0fa032578a6abd4a7bfc6162922cd4%2Fupdate-service-now-tickets-in-cd-stages-23.png?alt=media)
8. If you want to update multiple change tasks under a parent change request, select **Update Multiple**, and then do the following:

   * In **Change Request Number**, specify the change request whose tasks you want to update.
   * In **Change Task Type**, specify which task type you want to target. All tasks whose type matches your selection are updated. If you want all tasks under the parent to be updated regardless of their task type, leave this field blank.

   ![Update Multiple settings for change tasks under a parent change request](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-4da33d36df63260b305185fed864acc487da30f9%2Fupdate-service-now-tickets-in-cd-stages-25.png?alt=media)

{% hint style="info" %}
**Update Multiple for change tasks**

The **Update Multiple** option appears only if you select **Change Task** in the **Ticket Type** field.

This feature requires Harness Delegate version 80800 or later.
{% endhint %}

***

## Update fields <a href="#update-fields" id="update-fields"></a>

Perform the following steps to update fields in the ServiceNow ticket:

1. Select **Update Fields** to update specific ServiceNow fields in your ServiceNow ticket. This option enables you to access multiple custom fields from your ServiceNow integration.
2. (Applicable only if the ticket number is a fixed value) Scan the list of fields for a refresh icon, and then click the icon next to each field to fetch the latest value from ServiceNow. Harness displays the refresh icon next to a field only if that field has been updated in ServiceNow.

{% hint style="info" %}
**Refresh field values for fixed ticket numbers**

If the ticket number is a fixed value, and not a runtime value or expression, in addition to listing fields that have values, Harness does the following for you:

* It includes values from ServiceNow in the fields.
* If the value of a field has changed in ServiceNow, Harness includes a refresh icon that you can select if you want the field to show the updated value. Harness does not automatically update the field with the latest value.

This behavior requires the feature flag `CDS_SERVICENOW_FETCH_FIELDS`. Contact [Harness Support](mailto:support@harness.io) to enable the feature.
{% endhint %}

![ServiceNow Update fields list with refresh controls](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-c42a8f0967965b8db932745e25318c6275ab2693%2Fupdate-service-now-tickets-in-cd-stages-26.png?alt=media)

3. In **Description**, enter a detailed description of the ticket.
4. In **Short Description**, enter a summary of the ticket you are updating. This is the title of the ticket. You can use Harness variables in the **Short Description** and **Description** fields.

   ![Short Description and Description fields on the ServiceNow Update step](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-ec864a20eadb5ae12a026a4c8867ddf734c57947%2Fcreate-service-now-tickets-in-cd-stages-08.png?alt=media)
5. Select **Fields**. The **Add ServiceNow Fields** settings appear.
6. You can specify additional fields for the ticket by selecting **Provide Field List**. The properties are specified as key-value pairs, the name being the **field name** (not the label) in ServiceNow and a valid value.

***

## Use expressions in Ticket Number <a href="#use-expressions-in-ticket-number" id="use-expressions-in-ticket-number"></a>

In **Ticket Number**, you can use an expression or runtime input to reference the **Ticket Number** from another `Service Now Create` step. You can use this ticket number when you want to update or approve a particular ticket.

{% hint style="warning" %}
**Step order**

The `Service Now Create` step must be before the `Service Now Approval` and `Service Now Update` steps.
{% endhint %}

Suppose you have set up a [ServiceNow Create](/continuous-delivery/use-continuous-delivery/cd-building-blocks/cd-steps/ticketing-systems/create-service-now-tickets-in-cd-stages.md) step in your process. You want to use the Harness `Service Now Approval` step to approve the ticket, and once it is approved, you want to use the `Service Now Update` step to close it. You need the ticket number in both the Approval and Update steps. In this case, use the expression type in the **Ticket Number** field for both the Update and Approval steps.

![Ticket Number field set to an expression that references a Create step](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-a62977a0ac93738d4e8a2cfebfaa869bff681796%2Fticket_number.png?alt=media)

The following example YAML uses an expression in **Ticket Number**:

```yaml
  tags: {}
  stages:
    - stage:
        name: test
        identifier: test
        description: ""
        type: Approval
        spec:
          execution:
            steps:
              - step:
                  name: create
                  identifier: create
                  type: ServiceNowCreate
                  timeout: 5m
                  spec:
                    connectorRef: account.testSNow
                    ticketType: problem
                    fields:
                      - name: description
                        value: create ticket
                      - name: short_description
                        value: Try out expressions and update in the doc
                    createType: Normal
              - step:
                  type: ServiceNowUpdate
                  name: ServiceNowUpdate_1
                  identifier: ServiceNowUpdate_1
                  spec:
                    useServiceNowTemplate: false
                    connectorRef: account.testSNow
                    ticketType: problem
                    ticketNumber: <+execution.steps.create.ticket.ticketNumber>
                    fields:
                      - name: description
                        value: close
                      - name: short_description
                        value: close the ticket
                      - name: state
                        value: "4"
                  timeout: 10m
        tags: {}

```

When you run the pipeline and check the input of the `ServiceNowUpdate_1` step, you can see that the ticket number is retrieved from the expression `<+execution.steps.create.ticket.ticketNumber>`, as shown in the following screenshot:

![Ticket number retrieved from an expression in the ServiceNowUpdate\_1 step input](https://3694223630-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1JhZ4oKIppwY7d5AhPj%2Fuploads%2Fgit-blob-9e21e7726588854faed63d96ef5b746722121be6%2Fticket_number_expressions.png?alt=media)

***

## Apply from template <a href="#apply-from-template" id="apply-from-template"></a>

Perform the following steps to update a ticket using a form template:

1. Select **Apply From Template** to update a ticket using an existing form template.
2. In **Template Name**, enter the name of an existing template or provide an expression. All the fields corresponding to the Template are listed.
3. Select **Apply Changes**.

This option updates tickets with values as defined in the linked form template for the associated table. This is achieved via scripted APIs defined in the ServiceNow integration app for Harness templates.

***

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

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) to configure custom tables.

***

## Next steps

* [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): Create a ServiceNow ticket from a pipeline step.
* [Adding ServiceNow approval steps and stages](https://developer.harness.io/docs/platform/approvals/service-now-approvals): Add ServiceNow approvals to your pipeline.
* [ServiceNow create, update, and approval API permissions](/continuous-delivery/use-continuous-delivery/cd-building-blocks/cd-steps/ticketing-systems/servicenow-api-permission.md): Review the permissions the ServiceNow steps require.

{% @harness-feedback/feedback %}

[^1]: Beta features are feature-complete but still being validated. Available on request.
