{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":285,"path":"api-reference/cllent-mobile-api-reference/PaginatorAndroidAPI.md","title":"Paginator class - Android","bundle":null,"doc_type":null,"release":"australia","body":"\n# Paginator class- Android\n\nThe 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.\n\nYou must first call the [NowTableService - paginator\\(from tableName: String, configuration: FetchConfiguration? = nil\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/cllent-mobile-api-reference/NowTableServiceiOSAPI.md) or [NowTableService - paginator&lt;Model: Decodable&gt;\\(from tableName: String, path: String = Constants.resultPath, coder: Coder = .default, configuration: FetchConfiguration? = nil\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/cllent-mobile-api-reference/NowTableServiceiOSAPI.md) function to retrieve paginate return results.\n\n**Parent Topic:**[Mobile SDK - Android](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/cllent-mobile-api-reference/MobileSDKAndroidAPI.md)\n\n## Paginator - first\\(\\)\n\nFetches the first page of the return results.\n\nThe method throws a `PaginationError` if it cannot fetch the first page.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|None| |\n\nThe following code example shows how to call this function.\n\n```\nsuspend fun createAttachmentMetadataPaginator() {\n  val paginator = nowServiceManager.getNowAttachmentService()?.attachmentMetadataPaginator(null, 10)\n    ?.observe(object : PaginatorCallBack<NowAttachmentMetadata> {\n      override fun onFailure(e: NowDataError) {\n        handleError(e)\n      }\n\n      override fun onSuccess(response: Response<List<NowAttachmentMetadata>>) {\n        handleResponse(response)\n      }\n\n    })\n    ?: throw Exception(\"Response is null\")\n\n  paginator.first()\n}\n```\n\n## Paginator - hasNext\\(\\)\n\nChecks whether there is a next page in the return results.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_gxz_rww_rqb\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates whether there’s a next page in the return results.Possible values:\n\n-   true: Next page available.\n-   false: No next page available.\n\n</td></tr></tbody>\n</table>The following code example shows how to call this function.\n\n```\nsuspend fun createAttachmentMetadataPaginator() {\n  val paginator = nowServiceManager.getNowAttachmentService()?.attachmentMetadataPaginator(null, 10)\n    ?.observe(object : PaginatorCallBack<NowAttachmentMetadata> {\n      override fun onFailure(e: NowDataError) {\n        handleError(e)\n      }\n\n      override fun onSuccess(response: Response<List<NowAttachmentMetadata>>) {\n        handleResponse(response)\n      }\n\n    })\n    ?: throw Exception(\"Response is null\")\n\n  if (paginator.hasNext() && !paginator.isBusy()) {\n    paginator.next()\n  }\n}\n```\n\n## Paginator - hasPrevious\\(\\)\n\nChecks whether there in a previous page in the return results.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_ry4_dxw_rqb\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates whether there is a previous page in the return results.Possible values:\n\n-   true: Previous page available.\n-   false: No previous page available.\n\n</td></tr></tbody>\n</table>The following code example shows how to call this function.\n\n```\nsuspend fun createAttachmentMetadataPaginator() {\n  val paginator = nowServiceManager.getNowAttachmentService()?.attachmentMetadataPaginator(null, 10)\n    ?.observe(object : PaginatorCallBack<NowAttachmentMetadata> {\n      override fun onFailure(e: NowDataError) {\n        handleError(e)\n      }\n\n      override fun onSuccess(response: Response<List<NowAttachmentMetadata>>) {\n        handleResponse(response)\n      }\n\n    })\n    ?: throw Exception(\"Response is null\")\n\n  if (paginator.hasPrevious() && !paginator.isBusy()) {\n    paginator.previous()\n  }\n}\n```\n\n## Paginator - isBusy\\(\\)\n\nChecks whether the Paginator is busy fetching data.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_x3d_cyw_rqb\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nNone\n\n</td><td>\n\nFlag that indicates whether the Paginator is busy fetching data.Possible values:\n\n-   true: Busy fetching data.\n-   false: Not busy.\n\n</td></tr></tbody>\n</table>The following code example shows how to call this function.\n\n```\nsuspend fun createAttachmentMetadataPaginator() {\n  val paginator = nowServiceManager.getNowAttachmentService()?.attachmentMetadataPaginator(null, 10)\n    ?.observe(object : PaginatorCallBack<NowAttachmentMetadata> {\n      override fun onFailure(e: NowDataError) {\n        handleError(e)\n      }\n\n      override fun onSuccess(response: Response<List<NowAttachmentMetadata>>) {\n        handleResponse(response)\n      }\n\n    })\n    ?: throw Exception(\"Response is null\")\n\n  if (paginator.hasNext() && !paginator.isBusy()) {\n    paginator.next()\n  }\n}\n```\n\n## Paginator - last\\(\\)\n\nFetches the last page of the return results.\n\nThe method throws a `PaginationError` if it cannot fetch the last page.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|None| |\n\nThe following code example shows how to call this function.\n\n```\nsuspend fun createAttachmentMetadataPaginator() {\n  val paginator = nowServiceManager.getNowAttachmentService()?.attachmentMetadataPaginator(null, 10)\n    ?.observe(object : PaginatorCallBack<NowAttachmentMetadata> {\n      override fun onFailure(e: NowDataError) {\n        handleError(e)\n      }\n\n      override fun onSuccess(response: Response<List<NowAttachmentMetadata>>) {\n        handleResponse(response)\n      }\n\n    })\n    ?: throw Exception(\"Response is null\")\n\n  if !paginator.isBusy()) {\n    paginator.last()\n  }\n}\n```\n\n## Paginator - next\\(\\)\n\nFetches the next page of the return results.\n\nThe method throws a `PaginationError` if there are no more pages to fetch.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|None| |\n\nThe following code example shows how to call this function.\n\n```\nsuspend fun createAttachmentMetadataPaginator() {\n  val paginator = nowServiceManager.getNowAttachmentService()?.attachmentMetadataPaginator(null, 10)\n    ?.observe(object : PaginatorCallBack<NowAttachmentMetadata> {\n      override fun onFailure(e: NowDataError) {\n        handleError(e)\n      }\n\n      override fun onSuccess(response: Response<List<NowAttachmentMetadata>>) {\n        handleResponse(response)\n      }\n\n    })\n    ?: throw Exception(\"Response is null\")\n\n  if (paginator.hasNext() && !paginator.isBusy()) {\n    paginator.next()\n  }\n}\n```\n\n## Paginator - observe\\(callback: PaginatorCallBack&lt;T&gt;\\)\n\nSets the Paginator object's callbacks. You must call this method before calling any other Paginator functions.\n\n<table id=\"table_yj5_yyw_rqb\" class=\"parameters\"><thead><tr><th>\n\nName\n\n</th><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\ncallback\n\n</td><td>\n\nPaginatorCallBack\n\n</td><td>\n\nCallbacks to call based on the success or failure of the Paginator creation.-   Success: `abstract fun onSuccess(response: Response<List<T>>)`\n-   Failure: `abstract fun onFailure(e: NowDataError)`\n\n</td></tr></tbody>\n</table>|Type|Description|\n|----|-----------|\n|None| |\n\nThe following code example shows how to call this function.\n\n```\nsuspend fun createAttachmentMetadataPaginator() {\n  val paginationCallBack = object : PaginatorCallBack<NowAttachmentMetadata> {\n    override fun onFailure(e: NowDataError) {\n      handleError(e)\n    }\n\n    override fun onSuccess(response: Response<List<NowAttachmentMetadata>>) {\n      handleResponse(response)\n    }\n\n  }\n\n  val paginator = nowServiceManager.getNowAttachmentService()?.attachmentMetadataPaginator(null, 10)\n    ?.observe(paginationCallBack)\n    ?: throw Exception(\"Response is null\")\n}\n```\n\n## Paginator - previous\\(\\)\n\nFetches the previous page of the return results.\n\nThe method throws a `PaginationError` if it cannot fetch the previous page.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|None| |\n\nThe following code example shows how to call this function.\n\n```\nsuspend fun createAttachmentMetadataPaginator() {\n  val paginator = nowServiceManager.getNowAttachmentService()?.attachmentMetadataPaginator(null, 10)\n    ?.observe(object : PaginatorCallBack<NowAttachmentMetadata> {\n      override fun onFailure(e: NowDataError) {\n        handleError(e)\n      }\n\n      override fun onSuccess(response: Response<List<NowAttachmentMetadata>>) {\n        handleResponse(response)\n      }\n\n    })\n    ?: throw Exception(\"Response is null\")\n\n  if (paginator.hasPrevious() && !paginator.isBusy()) {\n    paginator.previous()\n  }\n}\n```\n\n## Paginator - reset\\(\\)\n\nResets the Paginator back to the first page but doesn’t return the first page of the return results.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|None| |\n\nThe following code example shows how to call this function.\n\n```\nsuspend fun createAttachmentMetadataPaginator() {\n  val paginator = nowServiceManager.getNowAttachmentService()?.attachmentMetadataPaginator(null, 10)\n    ?.observe(object : PaginatorCallBack<NowAttachmentMetadata> {\n      override fun onFailure(e: NowDataError) {\n        handleError(e)\n      }\n\n      override fun onSuccess(response: Response<List<NowAttachmentMetadata>>) {\n        handleResponse(response)\n      }\n\n    })\n    ?: throw Exception(\"Response is null\")\n\n  paginator.reset()\n}\n```\n\n"}}