# ServiceNow

## Overview

The ServiceNow integration is intended for users who have ServiceNow set up as an IT Service Management/Ticket Management system.

A lot of IT teams or cloud teams use ServiceNow as a single pane of glass for their Incident Management.

With this integration, we have covered most of the incident-related functionalities.

## Use Cases

The integration between Fylamynt and ServiceNow lets you:

* Trigger a workflow in Fylamynt, Ingest incidents as a trigger to Fylamynt workflows. (Fetch ServiceNow incidents into Fylamynt)
* ServiceNow Create Incident - Create a new ServiceNow Incident
* ServiceNow Delete Incident - Delete a specific ServiceNow Incident
* ServiceNow Search Incidents - Get the incident list according to the supplied query
* ServiceNow Update Incident - Update a specific ServiceNow Incident

## Configure ServiceNow in Fylamynt

* Navigate to **Settings** > **Integrations** > **ServiceNow**
* Configure a new integration instance

Details needed to set up **ServiceNow instance** in **Fylamynt**:

<table data-header-hidden><thead><tr><th>Parameter</th><th width="360.3333333333333">Description</th><th>Required</th></tr></thead><tbody><tr><td>Parameter</td><td>Description</td><td>Required</td></tr><tr><td>ServiceNow Instance URL</td><td>ServiceNow instance URL</td><td>True</td></tr><tr><td>ServiceNow User Password</td><td>Password for authorized user on ServiceNow instance</td><td>True</td></tr><tr><td>ServiceNow Username</td><td>Username for authorized user on ServiceNow instance</td><td>True</td></tr><tr><td>Webhook API Key Name</td><td>The Fylamynt API key to use for incoming ServiceNow webhooks.</td><td>False</td></tr><tr><td>ServiceNow Webhook URL</td><td>Fylamynt Webhook URL to be used by ServiceNow</td><td>True</td></tr></tbody></table>

### Setting up ServiceNow integration

In order to integrate Fylamynt with ServiceNow, you first need to set up a role user on your ServiceNow instance.

* Log in to your ServiceNow instance with an admin account.
* Go to the users table and click "New".
* Fill out the User ID, Email, First Name, Last Name, and Password fields.
* Make sure "Active" is checked. Optionally, you can also check the "Web services access only" box.
* Make sure "Password needs reset" and "Locked out" are unchecked.
* Click "Submit".

On the Fylamynt side

* Create an API Key to use for ServiceNow webhooks.
  * On the Fylamynt Settings page, scroll to the bottom, and click "API Keys".
  * Click "Add New".
  * Enter a name for the API Key.
* Return to Settings / ServiceNow.
* Enter your ServiceNow instance's URL. For example: "<https://dev12345.service-now.com>".
* Enter the username and password for the ServiceNow user you created earlier in the right-hand sidebar.
* Select the API Key you created in Fylamynt from the dropdown list of API keys.
* Click "Authorize".

### Setting up Webhook Trigger Action for ServiceNow

1. In your ServiceNow instance navigate to Outbound->REST Message
2. Click "New"
3. Give the Outbound REST call a name and a short description.
4. Copy the "Webhook URL" from the Fylamynt ServiceNow configuration and paste it into the "endpoint" field.
5. Leave "Authentication" set to "No Authentication"
6. Click "Submit".
7. Find the REST Message you just created in the list and re-open it.
8. There will be an "HTTP Methods" section that wasn't there before. Click "New" next to "HTTP Methods".
9. Name it "POSTCall"
10. Select "POST" from the HTTP method dropdown.
11. In the "HTTP Request" tab, add the following to the headers:
    * x-api-key : copy the key value from the Fylamynt API Key you created above and paste in in the value.
    * accept : application/json
    * Content-Type : application/json
12. In the "Content" text box, paste the following JSON (this is just an example, you may add more fields from the incident table as needed)&#x20;

    ```
    	{
    		"sys_id":"${sys_id}",
    		"number":"${number}",
    		"short_description": "${short_description}",
    		"urgency": "${urgency}",
    		"description": "${description}",
    		"impact": "${impact}",
    		"state": "${state}",
    	   "instance_id":"${instance_id}"
    	}
    ```
13. Click "Submit".
14. Re-open the HTTP Method you just created.
15. In the "Related Links" list, click "Auto-generate variables"
16. Click "Update".
17. Navigate to "Business Rules".
18. Click "New"
19. For the new Business Rule, enter a name, select a table ('incident' is the default ServiceNow incident database table)
20. Check "Active" and "Advanced"
21. In the "Advanced" tab, enter the following JavaScript. (This is just an example. Feel free to edit this code to include/exclude whichever fields you require.)
    * Be sure to change 'YourOutboundRestCall' to the name you gave your outbound rest call above.
    * Also make sure the second argument to sn\_ws.RESTMessageV2() is the name of the HTTP Method you created above.&#x20;

      ```
      (function executeRule(current, previous /*null when async*/ ) {

          // Add your code here
          function jsonEncode(str) {
              str = new JSON().encode(str);
              return str.substring(1, str.length - 1);
          }

          try {
              var r = new sn_ws.RESTMessageV2('YourOutboundRestCall', 'POSTCall');
              r.setStringParameter("sys_id", current.sys_id);
              r.setStringParameter("number", current.number);
              r.setStringParameter("short_description", current.short_description);
              r.setStringParameter("urgency", current.urgency);
              r.setStringParameter("description", jsonEncode(current.description + ''));
              r.setStringParameter("impact", current.impact);
              r.setStringParameter("state", current.state);
              r.setStringParameter("instance_id", gs.getProperty("instance_name"));
      		
              var response = r.execute();
              var responseBody = response.getBody();
              var httpStatus = response.getStatusCode();
              gs.log("getBody: " + response.getBody());
              gs.log("getStatusCode: " + response.getStatusCode());
              gs.log("getHeaders " + response.getHeaders());
          } catch (ex) {
              var message = ex.message;
          }

      })(current, previous);
      ```
22. In the "When to run" tab, select "after" from the dropdown and check "insert".
23. You can add other conditions as you see fit.
24. Click "Submit"

Now when you create a new incident in the incident table, a call will be made to Fylamynt containing the JSON you provided in step 12 above, populated with the fields in the new incident.

To take action when this message is received, create a new Fylamynt workflow and add a ServiceNow\_Alert action to it.

## Integration Actions

Fylamynt supports the following ServiceNow actions in workflows:

1. [Create a new ServiceNow Incident](#create-servicenow-issue)
2. [Delete a ServiceNow Incident](#delete-a-servicenow-incident)
3. [Search a ServiceNow Incident](#search-servicenow-issues)
4. [ServiceNow Alert Trigger](#servicenow-alert-trigger)
5. [Update a ServiceNow Incident](#update-a-servicenow-incident)

### Create a new ServiceNow Incident <a href="#create-servicenow-issue" id="create-servicenow-issue"></a>

Creates a new incident in ServiceNow

#### **Input**

| Parameter Name     | Required |
| ------------------ | -------- |
| table              | True     |
| short\_description | True     |
| caller             | True     |
| urgency            | False    |
| severity           | False    |
| assigned\_to       | False    |
| caller\_id         | False    |
| category           | False    |
| description        | False    |
| due\_date          | False    |
| made\_sla          | False    |
| incident\_state    | False    |
| impact             | False    |
| number             | False    |
| priority           | False    |
| template           | False    |
| state              | False    |

**Output**

| Parameter name | Type   | Description                         |
| -------------- | ------ | ----------------------------------- |
| Result         | Object | JSON of the newly created incident. |

### Delete a ServiceNow Incident

Delete the specified incident.

**Input**

| Parameter Name | Description                      | Required |
| -------------- | -------------------------------- | -------- |
| table          | The ServiceNow table to update   | True     |
| sys\_id        | The ID of the incident to update | True     |

**Output**

* Delete doesn't return a result.

### Search a ServiceNow Incident <a href="#search-servicenow-issues" id="search-servicenow-issues"></a>

Return the results of a ServiceNow query. Because the results might be very large, you can provide the name of an S3 bucket to save the non-truncated results.

See:[ ![](https://docs.servicenow.com/favicon.ico)Operators available for filters and queries](https://docs.servicenow.com/bundle/istanbul-servicenow-platform/page/use/common-ui-elements/reference/r_OpAvailableFiltersQueries.html)

**Input**

| Parameter Name | Description                                    | Required |
| -------------- | ---------------------------------------------- | -------- |
| query          | Query formatted per ServiceNow query syntax.   | True     |
| table          | The ServiceNow table to run the query against. | True     |
| s3\_bucket     | S3 bucket to save the full result list.        | False    |

**Output**

| Parameter name        | Type        | Description                                                                                  |
| --------------------- | ----------- | -------------------------------------------------------------------------------------------- |
| result                | JSON object | The output of the query.                                                                     |
| is\_result\_truncated | Boolean     | If the result is too large (>\~100k) the results will be truncated to the first 5 incidents. |
| result\_bucket\_key   | String      | If an S3 bucket is specified, the path to the data.                                          |
| s3\_bucket            | String      | The bucket specified in the input.                                                           |

### ServiceNow Alert Trigger

The integration node triggers the automatic execution of a workflow from a selected **ServiceNow Category**.

When creating a workflow, you are presented with a wizard to select the trigger type to use.

* On the workflow page, select **New Workflow**
* Enter the name of the Workflow.
* Select the **ServiceNow** trigger type.
* Click **Create Workflow**
* ![](https://2168485084-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MXYvxfYq9m2JdKqaCdk%2Fuploads%2FF4TFOGDkFTGwOT57OfKF%2Fimage.png?alt=media\&token=da27cabb-5413-4cb5-8fe0-7b651ea4ae88)

#### Configure the automatic execution of a workflow <a href="#fylamynt-task-management" id="fylamynt-task-management"></a>

To automatically run the workflow with the ServiceNow Alert trigger, the incident type and assignment need to be configured. Follow the step-by-step instructions provided on the[ Incident Management - Automatic workflow execution](https://docs.fylamynt.com/getting-started-1/7.-incident-management-automatic-workflow-execution) page.

### Update a ServiceNow Incident

Given an incident to update, update the provided fields.

**Input**

| Parameter Name                           | Description                     | Required |
| ---------------------------------------- | ------------------------------- | -------- |
| table                                    | The ServiceNow table to update. | True     |
| sys\_id The ID of the incident to update | True                            |          |
| short\_description                       | String                          | False    |
| urgency                                  |                                 | False    |
| severity                                 |                                 | False    |
| assigned\_to                             |                                 | False    |
| caller\_id                               |                                 | False    |
| category                                 |                                 | False    |
| description                              |                                 | False    |
| due\_date                                |                                 | False    |
| made\_sla                                |                                 | False    |
| incident\_state                          |                                 | False    |
| number                                   |                                 | False    |
| priority                                 |                                 | False    |
| template                                 |                                 | False    |
| state                                    |                                 | False    |
| caller                                   |                                 | False    |

**Output**

| Parameter name | Type | Description |
| -------------- | ---- | ----------- |

| Parameter name | Type        | Description          |
| -------------- | ----------- | -------------------- |
| result         | JSON Object | The updated incident |

###

###
