# Quickstart - Objects and Attachments

> The purpose of this guide is to help you create a working sample that uses the following ServiceNow activities:

## Overview

The purpose of this guide is to help you create a working sample that uses the following ServiceNow activities:

* [Insert ServiceNow Record](https://docs.uipath.com/activities/other/latest/legacy-integrations/servicenow-insert-servicenow-record)
* [Add Attachment](https://docs.uipath.com/activities/other/latest/legacy-integrations/servicenow-add-attachment)
* [Download Attachment](https://docs.uipath.com/activities/other/latest/legacy-integrations/servicenow-download-attachment)
* [Delete Attachment](https://docs.uipath.com/activities/other/latest/legacy-integrations/servicenow-delete-attachment)
* [Get ServiceNow Record](https://docs.uipath.com/activities/other/latest/legacy-integrations/servicenow-get-servicenow-record)
* [Delete ServiceNow Record](https://docs.uipath.com/activities/other/latest/legacy-integrations/servicenow-delete-servicenow-record)

This working sample enables you to quickly verify the connection to your ServiceNow instance and get familiar with the activity's input/output datatypes.

After completing the steps in this guide, you'll have an automation sequence that does the following:

1. Establishes a connection to your ServiceNow instance ([ServiceNow Scope](https://docs.uipath.com/activities/other/latest/legacy-integrations/servicenow-scope)).
2. Creates a new ServiceNow incident ([Insert ServiceNow Record](https://docs.uipath.com/activities/other/latest/legacy-integrations/servicenow-insert-servicenow-record)).
3. Uploads a file to the new incident ([Add Attachment](https://docs.uipath.com/activities/other/latest/legacy-integrations/servicenow-add-attachment)).
4. Downloads the uploaded file to a local folder ([Download Attachment](https://docs.uipath.com/activities/other/latest/legacy-integrations/servicenow-download-attachment)).
5. Deletes the uploaded file ([Delete Attachment](https://docs.uipath.com/activities/other/latest/legacy-integrations/servicenow-delete-attachment)).
6. Verifies the file was deleted by trying to retrieve the attachment record and outputting the expected error message ([Get ServiceNow Record](https://docs.uipath.com/activities/other/latest/legacy-integrations/servicenow-get-servicenow-record), [If](https://docs.uipath.com/studio/docs/the-if-activity)).
7. Deletes the created incident ([Delete ServiceNow Record](https://docs.uipath.com/activities/other/latest/legacy-integrations/servicenow-delete-servicenow-record)).

   ![docs image](https://dev-assets.cms.uipath.com/assets/images/activities/legacy-integrations-docs-image-187610-3395f6ce-1b4a93fe.webp)

## Prerequisites

Before you begin:

1. Complete the ServiceNow [Setup](https://docs.uipath.com/add-ins/other/latest/user-guide/servicenow-setup) steps.
2. A local file to attach to a ServiceNow record.

## Steps

### Build your project

1. Add a activity.
2. Enter the **AssetName** for the credential asset you created (during the **Setup**) for your ServiceNow instance username and password (e.g., *"ServiceNowSignin"*).
3. Create and enter a `SecureString` variable for your **Password** value (e.g., *password*).
4. Create and enter a `String` variable for your **Username** value (.e.g, *username*).
5. Add a second **Get Credential** activity.
6. Enter the **AssetName** for the credential asset you created (during the **Setup**) for your ServiceNow instance Client Id and Client Secret (e.g., *"ServiceNowClients"*).
7. Create and enter a `SecureString` variable for your **Password** value (e.g., *clientSecret*).
8. Create and enter a `String` variable for your **Username** value (.e.g, *clientId*).
9. Add the [ServiceNow Scope](https://docs.uipath.com/activities/other/latest/legacy-integrations/servicenow-scope) activity after the two **Get Credential** activites.
10. In the **Client Secret** property, enter the `SecureString` variable you created for your Client Secret in the steps above (e.g., *clientSecret*).
11. In the **Client Id** property, enter the `String` variable you created for your Client Id (e.g., *clientId*).
12. In the **Password** property, enter the `SecureString` variable you created for your password in the steps above (e.g., *password*).
13. In the **Username** property, enter the `String` variable you created for your username (e.g., *clientId*).
14. Create and enter a `String` variable for your **EndpointURL** (e.g., *endpointURL*)
15. Add the [Insert ServiceNow Record](https://docs.uipath.com/activities/other/latest/legacy-integrations/servicenow-insert-servicenow-record) activity inside the **ServiceNow Scope** activity.
16. Click the **Configure** button inside the **Insert ServiceNow Record** activity (this opens the Object Wizard.
17. In **Select Object** drop-down list, select *Incident*.
18. Create and enter a `String` variable for the **sys_id** **Value** (e.g., *sysID*)
19. Using the **Add Single Field** textbox, enter *short_description*.
    * Enter a **short_description** **Value** (e.g., *"UiPath-Attachment"*).
20. Click **Done**.
21. Create and enter a `ResponseStatus` variable for the **ServiceNowStatus** value (e.g., *insertRecordResponse*).
22. Add a activity after the **Insert ServiceNow Record** activity.
23. Enter the following **Text**: *"Record created: "+insertRecordResponse.Success.ToString+" | sys_id: "+sysID* (where *sysID* is the variable created for the **sys_id** **Value** field above).

    ![docs image](https://dev-assets.cms.uipath.com/assets/images/activities/legacy-integrations-docs-image-178828-11f4f7c7-0c5977d1.webp)
24. Add the [Add Attachment](https://docs.uipath.com/activities/other/latest/legacy-integrations/servicenow-add-attachment) activity after the **Write Line** activity.
25. Click the **Configure** button inside the **Add Attachment** activity.
26. In the **Select Object** drop-down list, select *Incident*.
27. In the **FileName** property, enter the full path to your local file (e.g., *"C:\UiPath_Projects\DemoFile.docx"*) or click the **Choose File** button in the activity.
28. In the **ObjectSysId** property, enter the **sys_id** variable you created for the **Insert Record** activity (e.g., *sysID*)
29. Create and enter a `String` variable for the **AttachmentId** property (e.g., *attachmentId*).
30. Create and enter a `ResponseStatus` variable for the **ServiceNowStatus** value (e.g., *addAttachmentResponse*).
31. Add a activity after the **Insert ServiceNow Record** activity.
32. Enter the following **Text**: *"Attachment added: "+addAttachmentResponse.Success.ToString+ " | sys_id: "+attachmentId* (where *attachmentId* is the variable created for the **AttachmentId** property above).
33. Add the [Download Attachment](https://docs.uipath.com/activities/other/latest/legacy-integrations/servicenow-download-attachment) activity after the **Write Line** activity.
34. Enter the **FilePath** where you want to download the file (e.g., *"C:\UiPath_Projects\Downloads"*).
35. In the **SysId** property, enter the **AttachmentId** variable you created for the **Add Attachment** activity (e.g., *attachmentId*).
36. Add the [Delete Attachment](https://docs.uipath.com/activities/other/latest/legacy-integrations/servicenow-delete-attachment) activity after the **Download Attachment** activity.
37. In the **ObjectSysId** property, enter the **AttachmentId** variable you created for the **Add Attachment** activity (e.g., *attachmentId*).

    ![docs image](https://dev-assets.cms.uipath.com/assets/images/activities/legacy-integrations-docs-image-183753-2d53cd15-65f0f22d.webp)

### Test your project

1. Add the [Get ServiceNow Record](https://docs.uipath.com/activities/other/latest/legacy-integrations/servicenow-get-servicenow-record) activity after the **Delete Attachment** activity.
2. Click the **Configure** button inside the **Insert ServiceNow Record** activity.
3. In the **Select Object** drop-down list, select *Attachment*.
4. In the **sys_id** **Value** field, enter the **AttachmentId** variable you created for the **Add Attachment** activity (e.g., *attachmentId*)
5. Click **Done**.
6. Create and enter a `ResponseStatus` variable for the **ServiceNowStatus** value (e.g., *getRecordResponse*).
7. Add an activity after the **Get ServiceNow Record** activity.
8. In the **Condition** property, enter *getRecordResponse.Success=False And getRecordResponse.Message.Contains("No Record")* to determine if the attachment record was successfully deleted by checking the error message (where *getRecordResponse* is the variable your created for the **ServiceNowStatus** property above).
9. In the **Then** statement box, add a **Write Line** activity.
   1. In the **Text** property, enter *"Test passed: "+getRecordResponse.Message*.
   2. Add the [Delete ServiceNow Record](https://docs.uipath.com/activities/other/latest/legacy-integrations/servicenow-delete-servicenow-record) after the **Write Line** activity.
   3. Click the **Configure** button inside the **Add Attachment** activity.
   4. In the **Select Object** drop-down list, select *Incident*.
   5. In the **Id** property, enter the **sys_id** variable you created for the **Insert Record** activity (e.g., *sysID*).
   6. Create and enter a `ResponseStatus` variable for the **ServiceNowStatus** value (e.g., *deleteRecordResponse*).
10. Add a **Write Line** activity after the **Delete ServiceNow Record** activity.
    1. In the **Text** property, enter *"Record deleted: "+deleteRecordResponse.Success.ToString*.
11. In the **Else** statement box, add a **Write Line** activity.
    1. In the **Text** property, enter *"Test failed: "+getRecordResponse.Message*.
12. Click **Run** and verify the **Output** window includes the expected write line values.

    ![docs image](https://dev-assets.cms.uipath.com/assets/images/activities/legacy-integrations-docs-image-178968-f966d956-9ce9d291.webp)

You're done!

To learn more about the ServiceNow activities (including example property inputs/outputs), see the [Activities](https://docs.uipath.com/activities/other/latest/legacy-integrations/servicenow-activities) page for a complete activity list and links to the activity detail pages.
