# ServiceNow

{% hint style="info" %}
The following documentation is for **ServiceNow v2.0.0** *(BDK)*.
{% endhint %}

## Overview

ServiceNow is an enterprise IT service management platform that automates and streamlines business processes. This integration enables automated ticket creation, incident management, change requests, and IT workflow automation. Improve service delivery and operational efficiency through automated IT processes.

## Prerequisites

### 1. Required Books

The following Book(s) need to be added to your agent so it can learn and understand the automation procedures defined within them:

* **ServiceNow**

#### How to Add the Book(s)

1. Go to **Books** → **All Books**.
2. Search for the name of the book and click on it.
3. Click on <kbd>**Install**</kbd> or <kbd>**Add Connection**</kbd> to add the book to your agent.
4. If adding a connection, you'll be prompted for [**connectivity**](#connectivity) details.

## Connectivity

This section outlines the available methods for connecting to the Book, along with the required configuration details for each.

### Connect using Instance, Username and Password

Connects to a ServiceNow instance using the provided credentials.

| Label    | Description                                       | Type        |
| -------- | ------------------------------------------------- | ----------- |
| Instance | The instance ID for the ServiceNow instance.      | `text`      |
| Username | The username to log in to the ServiceNow account. | `text`      |
| Password | The password to log in to the ServiceNow account. | `sensitive` |

## Procedures

### to create a (record) in a table name

Creates a new record in a ServiceNow account.

**Input Concepts**

| Concept                        | Description                                         | Type                | Required | Default Value |
| ------------------------------ | --------------------------------------------------- | ------------------- | -------- | ------------- |
| [`record`](#servicenow-record) | The ServiceNow Record object to be created.         | `servicenow record` | Yes      | (no default)  |
| `table name`                   | The table name in which the record will be created. | `text`              | Yes      | (no default)  |

**Output Concepts**

| Concept                        | Description                                                       | Type                |
| ------------------------------ | ----------------------------------------------------------------- | ------------------- |
| [`record`](#servicenow-record) | A ServiceNow Record object representing the newly created record. | `servicenow record` |

**Examples**

Create a new incident in the 'incident' table with the specified attributes.

```generic
create a json
use the above as the incident
set the incident's "short_description" to "Test Incident"
set the incident's "urgency" to "1"
set the incident's "impact" to "1"
create the incident in "incident"
```

### to delete some records

Deletes records from ServiceNow using batch processing.

**Input Concepts**

| Concept                         | Description                | Type                | Required | Default Value |
| ------------------------------- | -------------------------- | ------------------- | -------- | ------------- |
| [`records`](#servicenow-record) | The records to be deleted. | `servicenow record` | Yes      | (no default)  |

**Examples**

Delete incidents in the 'incident' table.

```generic
...
use the above as the records
delete the records
```

### to retrieve some (records) from *servicenow*

![FILTER - CAPABLE](https://img.shields.io/static/v1?label=FILTER\&message=CAPABLE\&color=blue)

Retrieves a list of ServiceNow records based on the specified filters.

**Input Concepts**

| Concept      | Description                                    | Type   | Required | Default Value |
| ------------ | ---------------------------------------------- | ------ | -------- | ------------- |
| `table name` | The table name from which to retrieve records. | `text` | Yes      | (no default)  |
| `limit`      | The limit of objects brought by the call.      | `text` | No       | (no default)  |

**Output Concepts**

| Concept                         | Description                                                | Type                |
| ------------------------------- | ---------------------------------------------------------- | ------------------- |
| [`records`](#servicenow-record) | List of ServiceNow Records based on the specified filters. | `servicenow record` |

**Examples**

Retrieve all incidents from the 'incident' table.

```generic
retrieve some records from servicenow
    the table name is "incident"
```

Retrieve all incidents from the 'incident' table whose number is 'INC0010001'.

```generic
retrieve some records from servicenow whose number is "INC0010001"
    the table name is "incident"
```

Retrieve all incidents from the 'incident' table whose created date is after '2022-01-01'.

```generic
the date is "2024-02-25T12:30:00Z"
get the date as a datetime
use the above as the target
retrieve some records from servicenow whose "sys_created_on" is greater than the target
    the table name is "incident"
```

Retrieve 5 incidents from the 'incident' table.

```generic
retrieve some records from servicenow
    the table name is "incident"
    the limit is "5"
```

### to update a record

Updates a record in ServiceNow, identified by its incident number, with specified attributes and their new values.

**Input Concepts**

| Concept                        | Description                                 | Type                | Required | Default Value |
| ------------------------------ | ------------------------------------------- | ------------------- | -------- | ------------- |
| [`record`](#servicenow-record) | The ServiceNow Record object to be updated. | `servicenow record` | Yes      | (no default)  |

**Output Concepts**

| Concept                        | Description                         | Type                |
| ------------------------------ | ----------------------------------- | ------------------- |
| [`answer`](#servicenow-record) | The updated record from ServiceNow. | `servicenow record` |

**Examples**

Update an incident in the 'incident' table with the specified attributes.

```generic
...
use the above as the record
set the record's "short_description" to "Updated Incident"
set the record's urgency to "2"
set the record's impact to "2"
update the record
```

## Concepts

### Servicenow record

A dataclass for ServiceNow record.

| Field Name                 | Description                                 | Type                     |
| -------------------------- | ------------------------------------------- | ------------------------ |
| `short_description`        | The short description of the record.        | `optional[text]`         |
| `description`              | The description of the record.              | `optional[text]`         |
| `caller_id`                | The caller ID of the record.                | `optional[text]`         |
| `category`                 | The category of the record.                 | `optional[text]`         |
| `subcategory`              | The subcategory of the record.              | `optional[text]`         |
| `contact_type`             | The contact type of the record.             | `optional[text]`         |
| `assignment_group`         | The assignment group of the record.         | `optional[text]`         |
| `assigned_to`              | The assigned to of the record.              | `optional[text]`         |
| `priority`                 | The priority of the record.                 | `optional[text]`         |
| `severity`                 | The severity of the record.                 | `optional[text]`         |
| `impact`                   | The impact of the record.                   | `optional[text]`         |
| `urgency`                  | The urgency of the record.                  | `optional[text]`         |
| `location`                 | The location of the record.                 | `optional[text]`         |
| `business_service`         | The business service of the record.         | `optional[text]`         |
| `cmdb_ci`                  | The CMDB CI of the record.                  | `optional[text]`         |
| `comments`                 | The comments of the record.                 | `optional[text]`         |
| `additional_comments`      | The additional comments of the record.      | `optional[text]`         |
| `watch_list`               | The watch list of the record.               | `optional[list of text]` |
| `upon_reject`              | The upon reject of the record.              | `optional[text]`         |
| `notify`                   | The notify of the record.                   | `optional[text]`         |
| `number`                   | The number of the record.                   | `optional[text]`         |
| `sys_id`                   | The sys ID of the record.                   | `optional[text]`         |
| `sys_created_on`           | The sys created on of the record.           | `optional[text]`         |
| `table_name`               | The table name of the record.               | `optional[text]`         |
| `parent`                   | The parent of the record.                   | `optional[text]`         |
| `made_sla`                 | The made SLA of the record.                 | `optional[text]`         |
| `sys_updated_on`           | The sys updated on of the record.           | `optional[text]`         |
| `sys_updated_by`           | The sys updated by of the record.           | `optional[text]`         |
| `approval_history`         | The approval history of the record.         | `optional[text]`         |
| `opened_by`                | The opened by of the record.                | `optional[text]`         |
| `work_end`                 | The work end of the record.                 | `optional[text]`         |
| `approval_set`             | The approval set of the record.             | `optional[text]`         |
| `wf_activity`              | The workflow activity of the record.        | `optional[text]`         |
| `work_notes`               | The work notes of the record.               | `optional[text]`         |
| `correlation_display`      | The correlation display of the record.      | `optional[text]`         |
| `delivery_task`            | The delivery task of the record.            | `optional[text]`         |
| `work_start`               | The work start of the record.               | `optional[text]`         |
| `additional_assignee_list` | The additional assignee list of the record. | `optional[text]`         |
| `calendar_duration`        | The calendar duration of the record.        | `optional[text]`         |
| `close_notes`              | The close notes of the record.              | `optional[text]`         |
| `sys_class_name`           | The sys class name of the record.           | `optional[text]`         |
| `closed_by`                | The closed by of the record.                | `optional[text]`         |
| `follow_up`                | The follow up of the record.                | `optional[text]`         |
| `company`                  | The company of the record.                  | `optional[text]`         |
| `reassignment_count`       | The reassignment count of the record.       | `optional[text]`         |
| `activity_due`             | The activity due of the record.             | `optional[text]`         |
| `approval`                 | The approval of the record.                 | `optional[text]`         |
| `sla_due`                  | The SLA due of the record.                  | `optional[text]`         |
| `comments_and_work_notes`  | The comments and work notes of the record.  | `optional[text]`         |
| `due_date`                 | The due date of the record.                 | `optional[text]`         |
| `sys_mod_count`            | The sys mod count of the record.            | `optional[text]`         |
| `sys_tags`                 | The sys tags of the record.                 | `optional[text]`         |
| `escalation`               | The escalation of the record.               | `optional[text]`         |
| `upon_approval`            | The upon approval of the record.            | `optional[text]`         |
| `correlation_id`           | The correlation ID of the record.           | `optional[text]`         |
| `other_fields`             | Additional fields not explicitly mapped.    | `optional[json]`         |
