Retrieve attachments and attachment metadata
Summarize
Summary of Retrieve attachments and attachment metadata
The NowAttachmentService API allows ServiceNow customers to efficiently manage attachments within their instance. It supports CRUD operations for attachments and retrieval of attachment metadata, facilitating a streamlined process for handling files associated with specific records.
Show less
Key Features
- Upload Attachments: Attachments can be uploaded and associated with specific records in ServiceNow.
- Download Attachments: Users can download one or multiple attachments as needed.
- Delete Attachments: The API provides the ability to delete unwanted attachments.
- Validate Attachments: Attachments can be validated by comparing their computed hash with an expected hash.
- Retrieve Metadata: Users can download metadata generated during the attachment upload process.
- Pagination for Metadata: The service supports pagination when retrieving metadata for multiple attachments, enhancing the user experience with infinite scroll capabilities.
Key Outcomes
By utilizing the NowAttachmentService API, ServiceNow customers can effectively manage attachments, ensuring that important files are easily accessible and organized. The ability to validate, paginate, and retrieve metadata aids in maintaining data integrity and improving application performance.
The NowAttachmentService API enables you to perform CRUD operations on attachments and retrieve attachment metadata from your ServiceNow instance.
- Upload attachments to your ServiceNow instance and associated them to a specific record.
- Download one or more attachments.
- Delete attachments.
- Validate an attachment by comparing the computed hash of the attachment to the expected hash.
- Download attachment metadata. This metadata is generated by your ServiceNow instance when an attachment is uploaded.
For additional information on working with attachments, see Attachment API.
All NowAttachmentService methods provide three implementations for returning results data. One that calls a completion handler with the return results, one that preforms an
async/await, and another that returns a Combine publisher (deprecated). For example, each upload() method uploads and associates a specified attachment to a specified record. However, the NowAttachmentService - upload(data: Data, configuration: NowAttachmentUploadConfiguration, progressUpdate: @escaping ProgressUpdate, completion: @escaping (Result<NowAttachmentMetadata, NowDataError>)) method calls a completion handler with the return results, the NowAttachmentService - upload(data: Data, configuration: NowAttachmentUploadConfiguration, progressUpdate: @escaping ProgressUpdate) async throws method performs an async/await, and the NowAttachmentService - upload(data: Data, configuration: NowAttachmentUploadConfiguration, progressUpdate: @escaping ProgressUpdate) method returns a Combine publisher.
// Import the NowData framework
import NowData
func makeAttachmentService(instanceUrl: URL,
completion: @escaping ((Result<NowAttachmentService, NowServiceErrors>) → Void))Attachment metadata pagination
You can use the NowAttachmentService methods to download attachment
metadata for one or more attachments. When downloading metadata from multiple attachments,
you may want to use the NowAttachmentService - attachmentMetadataPaginator(filter: Filter, limit: Int) method, which returns a Paginator object that enables you to easily iterate over the potentially large
amount of data that is returned. You typically use paginated return results to provide
infinite scroll capabilities for data presented inside a UITableView, a UICollectionView
(UIKit), or a List (SwiftUI), or to simplify page iteration of results in general.
paginator.publisher
.subscribe(on: DispatchQueue.global())
.receive(on: DispatchQueue.main)
.sink { ... }
.store(in: &subscriptions)- first()
- last()
- next()
- previous()
- reset()
In addition, the Paginator object provides properties
that enable you to obtain insights into the paginated data. For additional details on these
properties and the available methods, see Paginator API - iOS.