> 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/service-reliability-management/use-srm/monitored-services/change-source/servicenow-change-source.md).

# Configure ServiceNow as a change source

You can configure ServiceNow as a custom change source to monitor incidents.

To configure ServiceNow as a change source, do the following:

1. [Add ServiceNow as a custom change source in the Harness SRM monitored service.](#add-servicenow-as-a-change-source)
2. [Obtain the Harness webhook from the SRM monitored service.](#copy-webhook-url)
3. [Integrate the Harness webhook with ServiceNow.](#integrate-harness-webhook-with-servicenow)

### Add ServiceNow as a change source <a href="#add-servicenow-as-a-change-source" id="add-servicenow-as-a-change-source"></a>

To add ServiceNow as a change source to a monitored service, do the following:

1. In your Harness project, go to **Service Reliability** > **Monitored Services**.\
   A list of monitored services is displayed.
2. Find the monitored service to which you want to add a custom change source, select **More Options** (⋮) next to it, and then select **Edit service**.\
   The Configurations page appears.
3. On the **Configurations** page, go to **Change Sources**, and then select **+ Add New Change Source**.
4. On the Edit Change Source page, under **Select Change Source**, choose **Incident** as **Provider Type**, and then select **Custom**.
5. Enter a name for the new change source. For example, ServiceNow.
6. Select **Submit**.\
   The custom incident change source is added to the monitored service. A webhook URL and cURL commands are generated.

   <figure><img src="/files/YHNabOHpj3L5wRS5tylT" alt=""><figcaption></figcaption></figure>

### Copy webhook URL <a href="#copy-webhook-url" id="copy-webhook-url"></a>

You need a webhook for configuration in ServiceNow. ServiceNow utilizes this webhook to send incident alerts to the monitored service in Harness SRM.

To copy the webhook URL from the monitored service, do the following:

1. From the list of monitored services, select the specific monitored service where you have added the ServiceNow incident change source.
2. Navigate to the **Configuration** tab.
3. In the **Configurations** tab, go to the **Change Sources** tab.
4. In the **Change Sources** section, a list of change sources that have been added to the monitored service is displayed. The webhook URL and cURL commands are displayed alongside the corresponding monitored services.
5. Locate the ServiceNow incident change source that you want to configure with ServiceNow, and then copy the webhook URL associated with the change source.

### Integrate Harness webhook with ServiceNow <a href="#integrate-harness-webhook-with-servicenow" id="integrate-harness-webhook-with-servicenow"></a>

You need to integrate the webhook you created in Harness SRM with ServiceNow to start receiving the incident alerts. This involves setting up the incident format, creating a business rule with correct conditions, and adding the Harness webhook to your ServiceNow account.

To receive incident alerts in ServiceNow using the webhook created in Harness SRM, follow these steps:

#### Create an incident record in ServiceNow <a href="#create-an-incident-record-in-servicenow" id="create-an-incident-record-in-servicenow"></a>

To create an incident record in ServiceNow, do the following:

1. In your ServiceNow account, navigate to **All** > **Incident**, and then select **New**. You can also select **New** from the **Incident list** view.
2. On the form, fill in the following fields:
   * **service**: Affected business service.
   * **short\_description**: A brief description of the incident.
   * **description**: Detailed explanation of the incident.
   * **environment**: You need to add this field manually in the form.

To learn more, go to [Create an incident](https://docs.servicenow.com/en-US/bundle/vancouver-it-service-management/page/product/incident-management/task/create-an-incident.html).

#### Create a business rule in ServiceNow <a href="#create-a-business-rule-in-servicenow" id="create-a-business-rule-in-servicenow"></a>

A business rule is essential to define trigger conditions and configure the Harness webhook in ServiceNow. Below are the steps to create a business rule that meets the requirements to use ServiceNow as a custom change source in Harness SRM.

1. In your ServiceNow account, navigate to **System Definition** > **Business Rules**, and then select **New**.\
   The settings page appears.

   <figure><img src="/files/A8xCM7aZL4XMZDlpl5YB" alt=""><figcaption></figcaption></figure>
2. In the **When to run** tab, set the conditions for the business rule. Ensure it includes the following conditions:
   * **When**: Specify when the rule should execute: "display", "before", "async", or "after" the database operation is complete.
   * **On which Operations**: Determine on which database operations the rule should execute.
   * **Conditions**: Define the conditions that must be met for the rule to execute.
3. In the **Advanced** tab, write a script to configure the webhook URL that you [copied in Harness SRM](#copy-webhook-url). Below is a sample script that you can modify according to your specific requirements:

<details>

<summary>Expand to view the sample script for the ServiceNow business rule.</summary>

```

(function executeRule(current, previous /*null when async*/ ) {
try {
   var r = new sn_ws.RESTMessageV2();
   r.setEndpoint("Harness webhook");
   r.setHttpMethod("post");
   r.setRequestHeader("content-type","application/json");
   r.setRequestHeader("X-Api-Key","Harness x-api-key");
   
   //Mandatory Variables
   var number = current.getValue("number");
   var user = current.getValue("sys_created_by");
   var created_at = current.getValue("sys_created_on");
   var long_created_at = new GlideDateTime(created_at).getNumericValue();
   var name = current.getValue("short_description");
   var description = current.getValue("description");
   var instanceURL = gs.getProperty('glide.servlet.uri');
   var link = instanceURL + current.getLink();
   //var service = current.getValue("service");
   //var environment = current.getValue("u_environment");

   var obj = {
      "eventIdentifier": number,
         "user": user,
         "startTime": long_created_at,
      "endTime": long_created_at,
         "eventDetail":{
         "description": description,
         "externalLinkToEntity": link,
         "name": name
      }
   };
   
   var body = JSON.stringify(obj);
   gs.info("Webhook body: " + body);
   r.setRequestBody(body);

   var response = r.execute();
   var httpStatus = response.getStatusCode();
} catch (ex) {
   var message = ex.message;
   gs.error("Error message: " + message);
}

gs.info("Webhook target HTTP status response: " + httpStatus);

})(current, previous);

```

</details>

4. Save the business rule.

To learn more, go to [Create a business rule](https://docs.servicenow.com/bundle/rome-application-development/page/script/business-rules/task/t_CreatingABusinessRule.html).

### View ServiceNow event in Harness SRM <a href="#view-servicenow-event-in-harness-srm" id="view-servicenow-event-in-harness-srm"></a>

When a ServiceNow incident is triggered, it generates a change event in the Harness monitored service for which you have configured ServiceNow as a custom change source. To view the ServiceNow change event in the Harness monitored service, follow these steps:

1. In your Harness project, go to **Service Reliability** > **Monitored Services**.\
   A list of monitored services is displayed.
2. Select the monitored service for which you have configured ServiceNow as a custom change source.
3. Inside the selected monitored service, go to the **Change Impact** tab. On the **Change Impac**t tab, the following detailed information about the ServiceNow incident is displayed:
   * **Time Line Graph**: Displays an **Incidents** line with an event icon. This icon indicates a ServiceNow incident.
   * **Changes Section**: Lists the ServiceNow incident along with other change incidents.

<figure><img src="/files/rPyZPDM7OPjHiE5f5RQp" alt=""><figcaption></figcaption></figure>

#### View ServiceNow incident Change card <a href="#view-servicenow-incident-change-card" id="view-servicenow-incident-change-card"></a>

1. In your Harness project, go to **Service Reliability** > **Monitored Services**.\
   A list of monitored services is displayed.
2. Select the monitored service for which you have configured ServiceNow as a custom change source.
3. In the **Changes** section, locate and select the specific ServiceNow incident for which you want to view the Change card. The Change card is displayed with the following information:
   * Source: Information about the source of the incident.
   * Description: A description of the incident.
   * Service health: The impact of the incident on service health.
   * Incident Link: A link that navigates you directly to the incident page in your ServiceNow account for more detailed information.

<figure><img src="/files/3CBgUMgW4Qqa4FQqxXsL" alt=""><figcaption></figcaption></figure>

FEEDBACK\_BUTTON
