Activities
latest
false
Classic Integrations Activities
Last updated Jul 17, 2024

Quickstart - Objects and Attachments

Overview

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

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).
  2. Creates a new ServiceNow incident (Insert ServiceNow Record).
  3. Uploads a file to the new incident (Add Attachment).
  4. Downloads the uploaded file to a local folder (Download Attachment).
  5. Deletes the uploaded file (Delete Attachment).
  6. Verifies the file was deleted by trying to retrieve the attachment record and outputting the expected error message (Get ServiceNow Record, If).
  7. Deletes the created incident (Delete ServiceNow Record).



Prerequisites

Before you begin:

  1. Complete the 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 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 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).



  24. Add the 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 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 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).



Test your project
  1. Add the 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 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.



You're done!

To learn more about the ServiceNow activities (including example property inputs/outputs), see the Activities page for a complete activity list and links to the activity detail pages.

  • Overview
  • Prerequisites
  • Steps

Was this page helpful?

Get The Help You Need
Learning RPA - Automation Courses
UiPath Community Forum
Uipath Logo White
Trust and Security
© 2005-2024 UiPath. All rights reserved.