---
sourceDocument: Xanadu API Reference
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/xanadu/api-reference

 Release :

    - xanadu

ft:locale :

    - en-US

ft:publication_title :

    - Xanadu API Reference

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# Paginator class - Android

# Paginator class - Android {#ariaid-title1}

* Release version: Xanadu
* 
* Updated August 1, 2024
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 4 minutes to read

The Paginator class provides functions for paging through the return
results passed back by a REST endpoint call, such as those returned by the
NowTableService class.

You must first call the [NowTableService - paginator(from tableName: String, configuration: FetchConfiguration? = nil)](https://servicenow-prod.fluidtopics.net/Mg9nOO4u3WPRvIqz4t9SUw#NTblServ-paginator_S_O "Creates a paginator that enables iterating through pages of records.") or
[NowTableService - paginator\<Model: Decodable\>(from tableName: String, path: String = Constants.resultPath, coder: Coder = .default, configuration: FetchConfiguration? = nil)](https://servicenow-prod.fluidtopics.net/Mg9nOO4u3WPRvIqz4t9SUw#NTblServ-paginator_S_S_S_O "Creates a paginator that enables the iteration of pages of decoded model(s) that handle nesting.") function to retrieve paginate return results.

## Paginator - first() {#ariaid-title2}

Fetches the first page of the return results.
The method throws a `PaginationError` if it cannot fetch the first page.
{#PaginatorAnd-first__table_fpc_bgv_kqb__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 1. Parameters]

{#PaginatorAnd-first__table_fpc_bgv_kqb} {#PaginatorAnd-first__table_gpc_bgv_kqb__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 2. Returns]

{#PaginatorAnd-first__table_gpc_bgv_kqb}  
The following code example shows how to call this function.

    suspend fun createAttachmentMetadataPaginator() {
      val paginator = nowServiceManager.getNowAttachmentService()?.attachmentMetadataPaginator(null, 10)
        ?.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")

      paginator.first()
    }

## Paginator - hasNext() {#ariaid-title3}

Checks whether there is a next page in the return results.
{#PaginatorAnd-hasNext__table_fxz_rww_rqb__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 3. Parameters]

{#PaginatorAnd-hasNext__table_fxz_rww_rqb} {#PaginatorAnd-hasNext__table_gxz_rww_rqb__entry__2}

| Type | Description |
|-|-|
| Boolean | Flag that indicates whether there's a next page in the return results. Possible values: * true: Next page available. * false: No next page available. |
[Table 4. Returns]

{#PaginatorAnd-hasNext__table_gxz_rww_rqb}  
The following code example shows how to call this function.

    suspend fun createAttachmentMetadataPaginator() {
      val paginator = nowServiceManager.getNowAttachmentService()?.attachmentMetadataPaginator(null, 10)
        ?.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")

      if (paginator.hasNext() && !paginator.isBusy()) {
        paginator.next()
      }
    }

## Paginator - hasPrevious() {#ariaid-title4}

Checks whether there in a previous page in the return results.
{#PaginatorAnd-hasPrevious__table_qy4_dxw_rqb__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 5. Parameters]

{#PaginatorAnd-hasPrevious__table_qy4_dxw_rqb} {#PaginatorAnd-hasPrevious__table_ry4_dxw_rqb__entry__2}

| Type | Description |
|-|-|
| Boolean | Flag that indicates whether there is a previous page in the return results. Possible values: * true: Previous page available. * false: No previous page available. |
[Table 6. Returns]

{#PaginatorAnd-hasPrevious__table_ry4_dxw_rqb}  
The following code example shows how to call this function.

    suspend fun createAttachmentMetadataPaginator() {
      val paginator = nowServiceManager.getNowAttachmentService()?.attachmentMetadataPaginator(null, 10)
        ?.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")

      if (paginator.hasPrevious() && !paginator.isBusy()) {
        paginator.previous()
      }
    }

## Paginator - isBusy() {#ariaid-title5}

Checks whether the Paginator is busy fetching data.
{#PaginatorAnd-isBusy__table_w3d_cyw_rqb__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 7. Parameters]

{#PaginatorAnd-isBusy__table_w3d_cyw_rqb} {#PaginatorAnd-isBusy__table_x3d_cyw_rqb__entry__2}

| Type | Description |
|-|-|
| None | Flag that indicates whether the Paginator is busy fetching data. Possible values: * true: Busy fetching data. * false: Not busy. |
[Table 8. Returns]

{#PaginatorAnd-isBusy__table_x3d_cyw_rqb}  
The following code example shows how to call this function.

    suspend fun createAttachmentMetadataPaginator() {
      val paginator = nowServiceManager.getNowAttachmentService()?.attachmentMetadataPaginator(null, 10)
        ?.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")

      if (paginator.hasNext() && !paginator.isBusy()) {
        paginator.next()
      }
    }

## Paginator - last() {#ariaid-title6}

Fetches the last page of the return results.
The method throws a `PaginationError` if it cannot fetch the last page.
{#PaginatorAnd-last__table_ipy_hgv_kqb__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 9. Parameters]

{#PaginatorAnd-last__table_ipy_hgv_kqb} {#PaginatorAnd-last__table_jpy_hgv_kqb__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 10. Returns]

{#PaginatorAnd-last__table_jpy_hgv_kqb}  
The following code example shows how to call this function.

    suspend fun createAttachmentMetadataPaginator() {
      val paginator = nowServiceManager.getNowAttachmentService()?.attachmentMetadataPaginator(null, 10)
        ?.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")

      if !paginator.isBusy()) {
        paginator.last()
      }
    }

## Paginator - next() {#ariaid-title7}

Fetches the next page of the return results.
The method throws a `PaginationError` if there are no more pages to
fetch.
{#PaginatorAnd-next__table_kj5_5cv_kqb__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 11. Parameters]

{#PaginatorAnd-next__table_kj5_5cv_kqb} {#PaginatorAnd-next__table_lj5_5cv_kqb__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 12. Returns]

{#PaginatorAnd-next__table_lj5_5cv_kqb}  
The following code example shows how to call this function.

    suspend fun createAttachmentMetadataPaginator() {
      val paginator = nowServiceManager.getNowAttachmentService()?.attachmentMetadataPaginator(null, 10)
        ?.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")

      if (paginator.hasNext() && !paginator.isBusy()) {
        paginator.next()
      }
    }

## Paginator - observe(callback: PaginatorCallBack\<T\>) {#ariaid-title8}

Sets the Paginator object's callbacks. You must call this method before calling any
other Paginator functions.
{#PaginatorAnd-observe_O__table_yj5_yyw_rqb__entry__3}

| Name | Type | Description |
|-|-|-|
| callback | PaginatorCallBack | Callbacks to call based on the success or failure of the Paginator creation. * Success: `abstract fun onSuccess(response: Response<List<T>>)` * Failure: `abstract fun onFailure(e: NowDataError)` |
[Table 13. Parameters]

{#PaginatorAnd-observe_O__table_yj5_yyw_rqb} {#PaginatorAnd-observe_O__table_zj5_yyw_rqb__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 14. Returns]

{#PaginatorAnd-observe_O__table_zj5_yyw_rqb}  
The following code example shows how to call this function.

    suspend fun createAttachmentMetadataPaginator() {
      val paginationCallBack = object : PaginatorCallBack<NowAttachmentMetadata> {
        override fun onFailure(e: NowDataError) {
          handleError(e)
        }

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

      }

      val paginator = nowServiceManager.getNowAttachmentService()?.attachmentMetadataPaginator(null, 10)
        ?.observe(paginationCallBack)
        ?: throw Exception("Response is null")
    }

## Paginator - previous() {#ariaid-title9}

Fetches the previous page of the return results.
The method throws a `PaginationError` if it cannot fetch the previous
page.
{#PaginatorAnd-previous__table_lby_sfv_kqb__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 15. Parameters]

{#PaginatorAnd-previous__table_lby_sfv_kqb} {#PaginatorAnd-previous__table_mby_sfv_kqb__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 16. Returns]

{#PaginatorAnd-previous__table_mby_sfv_kqb}  
The following code example shows how to call this function.

    suspend fun createAttachmentMetadataPaginator() {
      val paginator = nowServiceManager.getNowAttachmentService()?.attachmentMetadataPaginator(null, 10)
        ?.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")

      if (paginator.hasPrevious() && !paginator.isBusy()) {
        paginator.previous()
      }
    }

## Paginator - reset() {#ariaid-title10}

Resets the Paginator back to the first page but doesn't return the first page of the return results.
{#PaginatorAnd-reset__table_u1y_mgv_kqb__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 17. Parameters]

{#PaginatorAnd-reset__table_u1y_mgv_kqb} {#PaginatorAnd-reset__table_v1y_mgv_kqb__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 18. Returns]

{#PaginatorAnd-reset__table_v1y_mgv_kqb}  
The following code example shows how to call this function.

    suspend fun createAttachmentMetadataPaginator() {
      val paginator = nowServiceManager.getNowAttachmentService()?.attachmentMetadataPaginator(null, 10)
        ?.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")

      paginator.reset()
    }


