> For the complete documentation index, see [llms.txt](https://atlas.anywhere.now/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://atlas.anywhere.now/product-reference/dialogue-studio/dialogue-studio-example-flows/connect-servicenow.md).

# Connect to ServiceNow

Import two flows in Dialogue Studio that look up and create ServiceNow incidents for a self-service chat or voice bot.

This example connects Dialogue Studio to ServiceNow to look up an existing incident or create a new one. It can be used in a chat-based self-service bot or, combined with transcription, in a voicebot. Use it as a starting point for ServiceNow incident self-service.

## What it does

Two separate flows are provided: one looks up an incident by its number, and one creates a new incident with a short description. Both call the ServiceNow Table API over HTTP with basic authentication.

## Prerequisites

* A UCC configured with Dialogue Studio.
* A ServiceNow user with read/write permissions. For this example (retrieving and creating incidents), the user needs the following roles:
  * `itil`
  * `rest_api_explorer`
  * `rest_service`

## Lookup incident

### Preview

![ServiceNow incident lookup flow](https://2627137428-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FscZpnEdBjDgQmlVn1iLr%2Fuploads%2Fgit-blob-72b3c4677d8b9a45b40c0de925871d4c949a61ce%2Fservicenow-incident-lookup.png?alt=media)

### Import the flow

1. Log in to your Dialogue Studio environment.
2. Open or create a tab for the flow.
3. From the menu in the top right, select **Import** and add the JSON from [`flows/servicenow-incident-lookup.json`](https://github.com/AnywhereNow/atlas-docs/tree/main/product-reference/dialogue-studio/dialogue-studio-example-flows/flows/servicenow-incident-lookup.json).
4. Open the **Configure Service Now Url** change node and enter the URL of your ServiceNow environment, for example `https://demo-servicenow.com/`.
5. Open the **Request to ServiceNow** HTTP request node and enter the username and password of the ServiceNow user, using your approved secret handling process.
6. Open the **Get incident based on number** inject node and enter the last digits of the incident number you want to retrieve.
7. Select the blue box before the inject node to test the flow.
8. Use the debug sidebar to see the output and which debug node the result reached.

### How the flow works

* The **Get incident based on number** inject node starts the process with an incident number.
* The **Configure Service Now Url** change node sets the ServiceNow URL used by the request.
* The **Request to ServiceNow** node sends a GET request to `{ServiceNowUrl}/api/now/table/incident?sysparm_query=numberENDSWITH{incidentnumber}`.
* A **Check statusCode** switch verifies the response was `200`. If not, it logs "Failed to retrieve information."
* A **Check if results** switch checks whether any incident matched. If so, it logs the returned incident; if not, it logs "no results."

You can extend this pattern by telling the customer the result with a Say node, routing them with a Switch node, or following up in ServiceNow with another HTTP request node.

## Create incident

### Preview

![ServiceNow create-incident flow](https://2627137428-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FscZpnEdBjDgQmlVn1iLr%2Fuploads%2Fgit-blob-1371a55b97bbb27e285d63fed7446f7a1c500950%2Fservicenow-incident-create.png?alt=media)

### Import the flow

1. Log in to your Dialogue Studio environment.
2. Open or create a tab for the flow.
3. From the menu in the top right, select **Import** and add the JSON from [`flows/servicenow-incident-create.json`](https://github.com/AnywhereNow/atlas-docs/tree/main/product-reference/dialogue-studio/dialogue-studio-example-flows/flows/servicenow-incident-create.json).
4. Open the **Configure Service Now Url** change node and enter the URL of your ServiceNow environment, for example `https://demo-servicenow.com/`.
5. Open the **Request to ServiceNow** HTTP request node and enter the username and password of the ServiceNow user, using your approved secret handling process.
6. Open the **Create incident with short description** inject node and enter the description you want the case to have.
7. Select the blue box before the inject node to test the flow.
8. Use the debug sidebar to see the output and which debug node the result reached.

### How the flow works

* The **Create incident with short description** inject node sets `short_description` to a placeholder text and starts the flow.
* The **Configure Service Now Url** change node sets the ServiceNow URL and copies `short_description` into `payload.short_description`.
* The **Request to ServiceNow** node sends a POST request to `{ServiceNowUrl}/api/now/table/incident` with the payload.
* A **Check statusCode** switch verifies the response was `201` (Created). If so, it logs the returned incident; if not, it logs "Failed to create incident."

You can generate a direct link to the created incident with an expression such as:

```
"https://[tenant].service-now.com/nav_to.do?uri=incident.do?sys_id=" & payload.result.sys_id
```

## Safe fallback behavior

Both flows check the HTTP status code before treating the response as successful (`200` for lookup, `201` for create) and route failures to a dedicated debug node rather than continuing with an invalid response. The lookup flow separately distinguishes "no results" from a failed request, so your flow can tell a customer their incident number was not found instead of reporting a generic error.

## Verification

1. Lookup: trigger the inject node with a known incident's last digits and confirm the "Returned incident" debug entry shows the expected incident.
2. Lookup: trigger it with digits that do not match any incident and confirm "no results" fires instead of an error.
3. Create: trigger the inject node and confirm the "Returned incident" debug entry shows the newly created incident, including its `sys_id`.
4. Temporarily use invalid ServiceNow credentials on either flow and confirm the failure is logged rather than left unhandled.

## Related topics

* Go to [Simple voice bot (with Azure OpenAI)](/product-reference/dialogue-studio/dialogue-studio-example-flows/simple-voicebot-with-azure-openai.md) for the transcription pattern this scenario can pair with for a voice-based self-service bot.
* Go to [Dialogue Studio example flows](/product-reference/dialogue-studio/dialogue-studio-example-flows.md) for the full gallery of example flows.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://atlas.anywhere.now/product-reference/dialogue-studio/dialogue-studio-example-flows/connect-servicenow.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
