# ServiceNow Application Scope

> `UiPath.ServiceNow.Activities.ServiceNowScopeActivity`

`UiPath.ServiceNow.Activities.ServiceNowScopeActivity`

:::tip
While the ServiceNow Application Scope activity can use standard authentication (**UserName**) and (**Password**), it is highly recommend to use OAuth security for all your connections per the steps below.
:::

The ServiceNow activities uses the OAuth 1.0 protocol to establish an authenticated connection between UiPath and your ServiceNow instance. This connection authorizes a Robot to call the ServiceNow APIs and access resources on your behalf.

To enable authorization, you create an [OAuth application endpoint](https://docs.uipath.com/activities/other/latest/legacy-integrations/servicenow-setup) to your ServiceNow instance. Creating this endpoint generates an OAuth client application record, Client ID, and Client Secret to enable authenticated access to your instance.

After creating your endpoint, you enter your ServiceNow credentials along with the application endpoint URL, Client ID, and Client Secret in the **ServiceNow Application Scope** activity.

:::tip
Integration user **roles** should only be assigned the **minimum necessary permissions for performing the tasks enabled by the activities in this package** (e.g., *admin, itil, soap_ecc, and etc.* should not be used for integration user roles). Inbound web services that modify tables, should be restricted to the appropriate [system roles](https://docs.servicenow.com/bundle/orlando-platform-administration/page/administer/roles/reference/r_BaseSystemRoles.html). For more information, see the [Roles](https://docs.servicenow.com/bundle/orlando-platform-administration/page/administer/roles/concept/c_Roles.html) section in the ServiceNow documentation.
:::

## How it works

The following steps and message sequence diagram is an example of how the activity works from design time (i.e., the activity dependencies and input/output properties) to run time.

1. Complete the [Setup](https://docs.uipath.com/activities/other/latest/legacy-integrations/servicenow-setup) steps.
2. Add a activity for each `SecureString` input property (e.g., two total - one for **Password** and one for **ClientSecret**)
3. Add the **ServiceNow Application Scope** activity to your project.
4. Enter values for the [Authentication](https://docs.uipath.com/activities/other/latest/legacy-integrations/servicenow-scope#servicenow-application-scope) and [Connection](https://docs.uipath.com/activities/other/latest/legacy-integrations/servicenow-scope#servicenow-application-scope) properties.
5. Create and enter a `IConnection` variable for [Output](https://docs.uipath.com/activities/other/latest/legacy-integrations/servicenow-scope#servicenow-application-scope) properties.
   * You can use this variable in subsequent uses of the **ServiceNow Application Scope** activity.

     ![docs image](https://dev-assets.cms.uipath.com/assets/images/activities/legacy-integrations-docs-image-180400-484808b6-78ff57dd.webp)

If you encounter issues using standard authentication, please see [Standard Authentication Tips](https://docs.uipath.com/activities/other/latest/legacy-integrations/servicenow-scope#servicenow-application-scope).

### In the Body of the Activity

To build your project and enable the **Object Wizard** in other activities, you must use the **Connection Wizard** by clicking the **Configure** button.

To learn more, see the [Wizards](https://docs.uipath.com/activities/other/latest/legacy-integrations/servicenow-about) section in the **About** page.

## Properties

### Authentication

* **Username** - The username for your ServiceNow instance. Enter a `String` variable.
  + This value may be different from your ServiceNow account if you have multiple instances.
  + The **Username** is associated with the **Password**. It's recommended that you generate a `String` variable by following the [Create Credential Assets](https://docs.uipath.com/activities/other/latest/legacy-integrations/servicenow-setup) section of the **Setup** guide.
  + To enter your `String` variable, use a activity that outputs your Credential Asset (see [example](https://docs.uipath.com/activities/other/latest/legacy-integrations/servicenow-scope#servicenow-application-scope) below).
* **Password** - The password (associated with the **Username**) to your ServiceNow instance. Enter a `String` or `String` variable.
  + This value may be different from your ServiceNow account if you have multiple instances.
  + The **Username** is associated with the **Password**. It's recommended that you generate a `String` variable by following the [Create Credential Assets](https://docs.uipath.com/activities/other/latest/legacy-integrations/servicenow-setup) section of the **Setup** guide.
  + To enter your `String` variable, use a activity that outputs your Credential Asset (see [example](https://docs.uipath.com/activities/other/latest/legacy-integrations/servicenow-scope#servicenow-application-scope) below).
* **Client Secret** - The `SecureString` used to authorize communications between UiPath and your ServiceNow instance. Enter a `SecureString` variable.
  + The **ClientSecret** gets generated for your ServiceNow instance when you complete an application registry. For more information, see the [Setup OAuth](https://docs.uipath.com/activities/other/latest/legacy-integrations/servicenow-setup) section of the **Setup** guide.
  + To generate a `SecureString` variable, see the [Create Credential Assets](https://docs.uipath.com/activities/other/latest/legacy-integrations/servicenow-setup) section of the **Setup** guide.
  + To enter your `SecureString` variable, use a activity that outputs your Credential Asset (see [example](https://docs.uipath.com/activities/other/latest/legacy-integrations/servicenow-scope#servicenow-application-scope) below).
* **ClientId** - The auto-generated, unique ID of your application registry. Enter a `String` variable.
  + The **ClientId** gets generated for your ServiceNow instance when you complete an application registry. For more information, see the [Setup OAuth](https://docs.uipath.com/activities/other/latest/legacy-integrations/servicenow-setup) section of the **Setup** guide.
  + The ClientId is associated with the **ClientSecret**. It's recommended that you generate a `String` variable by following the [Create Credential Assets](https://docs.uipath.com/activities/other/latest/legacy-integrations/servicenow-setup) section of the **Setup** guide.
  + To enter your `String` variable, use a activity that outputs your Credential Asset (see [example](https://docs.uipath.com/activities/other/latest/legacy-integrations/servicenow-scope#servicenow-application-scope) below).
* **Local Port (Optional)** - The local port for redirect. Default value is `10001`. Enter a String or `String` variable.
* **Use OAuth 2.0** - Check this to use OAuth2 code grant flow of ServiceNow.

### Common

* **DisplayName** - The display name of the activity. Enter a `String` or `String` variable.

### Connection

* **EndpointURL** - The URL of your ServiceNow instance. Enter a `String` or `String` variable. The URL should be to your ServiceNow instance and not the **Redirect URL** in your application registry.

### Misc

* **Private** - If selected, the values of variables and arguments are no longer logged at Verbose level.

### Options

* **ReportApiErrorAsException** - When selected, API error responses are reported in BusinessActivityExecutionException by all child activities that use this application scope. When cleared, the child activity populates the API error message in the ResponseStatus output property and workflow execution continues. Check the ResponseStatus property to confirm successful execution.

### Output

* **ServiceNowConnection** - A record of your established connection that you can use in subsequent **ServiceNow Application Scope** activities. Enter a `IConnection` variable (*UiPath.BAF.Models.Connection.IConnection*).

### Use Existing Connection

* **ExistingServiceNowConnection** - A connection record from a parent **ServiceNow Application Scope** activity that you can use instead of establishing a new connection. Enter a `IConnection` variable (*UiPath.BAF.Models.Connection.IConnection*).
  + The `IConnection` variable must be from a previously run **SeriviceNow Scope** activity (parent) that still has an active connection.
  + If you're unable to establish a connection using this property, try re-running your parent **ServiceNow Application Scope** activity.

## Example

The following image shows an example of the activity dependency relationship and input/output property values.

For step-by-step instructions and examples, see the [Quickstart](https://docs.uipath.com/activities/other/latest/legacy-integrations/servicenow-quickstarts) guide.

![docs image](https://dev-assets.cms.uipath.com/assets/images/activities/legacy-integrations-docs-image-179748-e75ba072-9349733f.webp)

## Standard Authentication Tips

In the ServiceNow activity pack, the Basic Authentication (username and password) can be used to run activities. The steps are delineated below:

### Design Time

At Design Time enter the username and password with the endpoint URL and these details are saved. Note that the credentials are not validated with ServiceNow for basic authentication at the scope level. Only at a later stage when ServiceNow entities are fetched in an individual activity or at run time while running an activity are these basic authentication credentials used to authenticate.

![docs image](https://dev-assets.cms.uipath.com/assets/images/activities/legacy-integrations-docs-image-178159-c8f2f133-3402f93a.webp)

If the basic authentication credentials provided are incorrect, then while loading the entity list an error will be thrown as it uses the saved basic authentication credentials to connect to ServiceNow and get entities/table names.

![docs image](https://dev-assets.cms.uipath.com/assets/images/activities/legacy-integrations-docs-image-181168-441fdfa4-9920bb42.webp)

If the credentials (**Username**, **Password**, **EndpointUrl**) are correct the entities will be populated in the activity dropdown like below:

![docs image](https://dev-assets.cms.uipath.com/assets/images/activities/legacy-integrations-docs-image-180744-2edd47de-710797e5.webp)

### Runtime

Make sure the credentials are populated in the properties pane on the right.

![docs image](https://dev-assets.cms.uipath.com/assets/images/activities/legacy-integrations-docs-image-180452-fbf04dfb-e2bbf2e2.webp)

If the credentials are correct the activity will run. If incorrect it will throw error at run time as shown below:

![docs image](https://dev-assets.cms.uipath.com/assets/images/activities/legacy-integrations-docs-image-183669-0e61790f-2f9e2482.webp)
