NowTableService interface - Android

  • Release version: Yokohama
  • Updated January 30, 2025
  • 4 minutes to read
  • The NowTableService interface provides functions that enable you to create, read, delete, and update records within a table on a ServiceNow instance.

    Table 1. Properties
    Name Type Description
    configuration NowServiceConfiguration Configuration to associate with the service.

    NowTableService - createRecord(tableName: String, fields: Map<String, String>, writeOptions: FieldWriteOptions?, configuration: FieldReadConfiguration?)

    Inserts the specified record in the specified table.

    Table 2. Parameters
    Name Type Description
    tableName String Name of the table in which to save the record.
    fields Map<String, String> Key-value pairs for all fields to create in the record.
    Note:
    All fields within a record may not be available for update. For example, fields that have a prefix of sys_ are typically system parameters that are automatically generated and cannot be updated. Fields that are not specified and not auto-generated by the system are set to the associated data type's null value.
    writeOptions FieldWriteOptions Optional. Write options to set on the fields, such as whether the value should be stored as display values or whether to suppress auto generation of system fields.

    Default: null - No options selected

    configuration FieldReadConfiguration Optional. Configuration that specifies which fields to return for the created record and what to include in the fields.
    Table 3. Returns
    Type Description
    Call<ByteArray> Success: ByteArray that contains the created record. You can convert this information into any data model that you need.

    Failure: NowDataError

    fun createTableRecord( tableName: String, fields: KeyValues, includeFields: String, 
      readOptions: ReadOptions?, writeOptions: WriteOptions?){ 
     
      val readOptionsArray = readOptions?.asArray() ?: arrayOf() 
      val readConfig = FieldReadConfiguration(includeFields.split(","), *readOptionsArray) 
     
      var body:ByteArray? 
     
      val call = tableService.createRecord(tableName, fields.toMap(), 
        writeOptions?.asFieldWriteOptions(), 
        readConfig) 
      call.enqueue({ body = it.body },{ Log.d("Records", "failed to create record") }) 
    } 

    NowTableService - deleteRecord(sysId: String, tableName: String)

    Deletes the specified record in the specified table.

    Table 4. Parameters
    Name Type Description
    sysId String Sys_id of the record to delete.
    tableName String Name of the table in which the specified record is located, such as incident or asset.
    Table 5. Returns
    Type Description
    Call<ByteArray> Success: Nothing is returned.

    Failure: NowDataError

    fun deleteTableRecord( recordSysId: String, tableName: String, callType: CallTestType){ 
      val tableService = serviceProvider.tableService()
      var body:ByteArray? 
      val call = tableService.deleteRecord(recordSysId, tableName) 
      call.enqueue({ body = it.body },{ Log.d("Records", "failed to create record") }) 
    } 

    NowTableService - paginator(tableName: String, configuration: FetchConfiguration)

    Creates a paginator that allows iteration of pages of records within a table.

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

    Table 6. Parameters
    Name Type Description
    tableName String Name of the table for which to create the paginator.
    configuration FetchConfiguration Configuration that specified the filters to use, pagination page size limit, which fields to retrieve, and what to include in the fields.
    Table 7. Returns
    Type Description
    Paginator​<ByteArray> Success: Paginator with ByteArray output of the requested records. You can use the functions within the Paginator object to navigate the returned records.

    Failure: NowDataError

    private fun initTablePaginator() { 
      paginator = service?.paginator(tableName, FetchConfiguration(null, 3)) 
        ?.observe(object: PaginatorCallBack<ByteArray> { 
          override fun onSuccess(response: Response<List<ByteArray>>) { 
          } 
          override fun onFailure(e: NowDataError) { 
            Log.e("NowDataError", "", e) 
          } 
        }) 
    }

    NowTableService - record(sysId: String, tableName: String, configuration: FieldReadConfiguration?)

    Retrieves the specified record from the specified table.

    Table 8. Parameters
    Name Type Description
    sysId String Sys_id of the record to retrieve.
    tableName String Name of the table in which the specified record is located, such as incident or asset.
    configuration FieldReadConfiguration Optional. Configuration that specifies which fields to retrieve and what to include in the fields.
    Table 9. Returns
    Type Description
    Call​<ByteArray> Success: ByteArray that contains the retrieved record. You can convert this information into any data model that you need.

    Failure: NowDataError

    fun fetchTableRecord( sysId: String, tableName: String, includeFields: String, 
      readOptions: ReadOptions?){ 
     
      val readOptionsArray = readOptions?.asArray() ?: arrayOf() 
      val readConfig = FieldReadConfiguration(includeFields.split(","), *readOptionsArray) 
     
      var body:ByteArray? 
     
      val call = tableService.record(sysId, tableName, readConfig) 
      call.enqueue({ body = it.body },{ Log.d("Record", "failed fetching record") }) 
    }

    NowTableService - records(tableName: String, configuration: FieldReadConfiguration?)

    Retrieves sll records record from the specified table.

    Table 10. Parameters
    Name Type Description
    tableName String Name of the table from which to retrieve the records, such as incident or asset.
    configuration FieldReadConfiguration Optional. Configuration that specifies which fields to retrieve and what to include in the fields.
    Table 11. Returns
    Type Description
    Call​<ByteArray> Success: ByteArray that contains the retrieved records. You can convert this information into any data model that you need.

    Failure: NowDataError

    fun fetchTableRecords( tableName: String, filterQuery: String, includeFields: String, 
      readOptions: ReadOptions?, limit: Int?){ 
     
      val readOptionsArray = readOptions?.asArray() ?: arrayOf() 
      val readConfig = FieldReadConfiguration(includeFields.split(","), *readOptionsArray) 
      val config = FetchConfiguration(Filter(filterQuery), limit, readConfig) 
     
      var body:ByteArray? 
     
      val call = tableService.records(tableName, config) 
      call.enqueue({ body = it.body },{ Log.d("Records", "failed fetching records") }) 
    } 

    NowTableService - updateRecord(sysId: String, tableName: String, fields: Map<String, String>, writeOptions: FieldWriteOptions?, configuration: FieldReadConfiguration?)

    Updates the specified record in the specified table with the specified fields.

    Table 12. Parameters
    Name Type Description
    tableName String Name of the table in which to update the record.
    fields Map<String, String> Key-value pairs for all fields to update in the record.
    Note:
    All fields within a record may not be available for update. For example, fields that have a prefix of sys_ are typically system parameters that are automatically generated and cannot be updated. Fields that are not specified and not auto-generated by the system are set to the associated data type's null value.
    writeOptions FieldWriteOptions Optional. Write options to set on the fields, such as whether the value should be stored as display values or whether to suppress auto generation of system fields.

    Default: null - No options selected

    configuration FieldReadConfiguration Optional. Configuration that specifies which fields to update and what to include in the fields.

    Default: null

    Table 13. Returns
    Type Description
    Call​<ByteArray> Success: ByteArray that contains the updated record. You can convert this information into any data model that you need.

    Failure: NowDataError

    fun updateTableRecord( sysId: String, tableName: String, fields: KeyValues, includeFields: String, 
       readOptions: ReadOptions?, writeOptions: WriteOptions?){ 
     
       val readOptionsArray = readOptions?.asArray() ?: arrayOf() 
       val readConfig = FieldReadConfiguration(includeFields.split(","), *readOptionsArray) 
     
       var body:ByteArray? 
     
       val call = tableService.updateRecord(recordSysId, tableName, fields.toMap(), 
         writeOptions?.asFieldWriteOptions(), 
         readConfig) 
       call.enqueue({ body = it.body },{ Log.d("Records", "failed to update record") }) 
    }