Skip to content
Release: Australia · Updated: 2026-03-12 · Official documentation · View source

NowAttachmentService interface- Android

The NowAttachmentService interface provides functions that enable the manipulation of file attachments and their associated metadata.

NameTypeDescription
configurationNowServiceConfigurationConfiguration to associate with the service.

Parent Topic:Mobile SDK - Android

NowAttachmentService - attachment(sysId: String, validateAttachment: Boolean = true)

Retrieves the attachment with the specified sys_id and optionally validates the attachment by comparing the computed hash of the attachment to the expected hash.

NameTypeDescription
sysIdStringSys\_id of the attachment to retrieve. This is the sys\_id for the attachment on your ServiceNow instance.
validateAttachmentBooleanFlag that indicates whether to validate the attachment. Valid values: - true: Validate the attachment. - false: Do not validate the attachment. Default: true
TypeDescription
Call<NowAttachment>NowAttachment object that contains the requested attachment.
fun getAttachment(sysId: String, isValidateAttachment: Boolean) { 
  val call = attachmentService.attachment(sysId, isValidateAttachment) 
  call.enqueue( 
    { response -> 
      val attachment: NowAttachment? = response.body 
    }, 
      { nowDataError -> handleError(nowDataError) } 
  ) 
}

NowAttachmentService - attachmentMetadata(sysId: String)

Retrieves the metadata for the attachment associated with the specified sys_id.

NameTypeDescription
sysIdStringSys_id of the attachment whose metadata you want to retrieve.
TypeDescription
Call​<NowAttachmentMetadata>Object that contains the metadata for the specified attachment.
fun fetchMetadata(sysId: String) { 
  val call = attachmentService.attachmentMetadata(sysId) 
  call.enqueue(
    { response -> 
      val metadata: NowAttachmentMetadata? = response.body 
    },
    { nowDataError -> handleError(nowDataError) } 
  )
}

NowAttachmentService - attachmentMetadata(filter: Filter? = null, limit: Int? = null)

Retrieves the metadata for all the attachments that meet the specified criteria.

NameTypeDescription
filterFilterOptional. Query string to use to filter the attachments whose metadata to return.Default: null - Returns metadata for all available attachments. Takes into consideration the limit parameter.
limitIntegerOptional. Maximum number of attachment file's metadata to return.Default: null - Returns all metadata that meets the filter parameter specifications.
TypeDescription
Call<List​<NowAttachmentMetadata>>List of objects that contain the metadata for the matching attachments.
fun fetchMultipleMetadata(filterQuery: String, limit: Int) { 
  val call = attachmentService.attachmentMetadata(Filter(filterQuery), limit) 
  call.enqueue( 
    { response -> 
      val metadataList: List<NowAttachmentMetadata>? = response.body 
    },
    { nowDataError -> handleError(nowDataError) } 
  )
}

NowAttachmentService - attachmentMetadataPaginator(filter: Filter? = null, limit: Int? = null)

Retrieves the metadata for all the attachments that meet the specified criteria and creates a paginator for iterating through the pages of the returned metadata.

You can use this paginator to navigate through the returned metadata, performing navigation operations such as fetching the first, last, previous, or next page, or checking whether there is next or previous page.

NameTypeDescription
filterFilterOptional. Query string to use to filter the attachments whose metadata to return.Default: null - Returns metadata for all available attachments. Takes into consideration the limit parameter.
limitIntegerOptional. Maximum number of attachment file's metadata to return.Default: null - Returns all metadata that meets the filter parameter specifications.
TypeDescription
Paginator​<NowAttachmentMetadata>Success: Paginator object along with the specified pages of metadata. Failure: NowDataError object.

The following code example shows how to call this function.

suspend fun createAttachmentMetadataPaginator() {
  val filterQuery: String = "content_type=text/plain"
  val filter = filterQuery.let(::Filter)
  val limit = 10
  val paginator = nowServiceManager.getNowAttachmentService()?.attachmentMetadataPaginator(filter, limit)
    ?.observe(object : PaginatorCallBack<NowAttachmentMetadata> {
      override fun onFailure(e: NowDataError) {
        handleError(e)
      }

      override fun onSuccess(response: Response<List<NowAttachmentMetadata>>) {
        handleResponse(response)
      }

    })
    ?: throw Exception("Response is null")
}

NowAttachmentService - delete(sysId: String)

Deletes the attachment with the specified sys_id.

NameTypeDescription
sysIdStringSys_id of the attachment to delete.
TypeDescription
Call<ByteArray>Success: Nothing is returned.Failure: NowDataError returned.
fun deleteAttachment(sysId: String) { 
  val call = attachmentService.delete(sysId) 
  call.enqueue( 
    { response -> handleResponse(response) }, 
    { nowDataError -> handleError(nowDataError) } 
  )
} 

NowAttachmentService - upload(data: ByteArray, configuration: NowAttachmentUploadConfiguration)

Retrieves the metadata for all the attachments that meet the specified criteria and creates a paginator for iterating through pages of the returned metadata.

NameTypeDescription
dataByteArrayMetadata to upload and associate with the attachment specified in the configuration object.
configurationNowAttachmentUploadConfigurationUpload configuration parameters.
TypeDescription
NowAttachmentMetadataUploaded metadata.
fun uploadAttachment(tableName: String, recordSysId: String, fileName: String) { 
  val bitmap = BitmapFactory.decodeResource(resources, R.drawable.test_image) 
  val data = bitmap.compress(ImageType.JPEG) 
  val contentType = "image/jpg" 
  val config = NowAttachmentUploadConfiguration(tableName, recordSysId, fileName, contentType) 
  val call = attachmentService.upload(data, config) 

  call.enqueue( 
    { response -> 
      val uploadedAttachmentMetadata: NowAttachmentMetadata? = response.body 
    },
    { nowDataError -> handleError(nowDataError) } 
  )
}