Get all records (the offset method)

Introduction

This article shows how to retrieve information of all records from an App using the offset method. This method is the simplest and most popular way of retrieving all records from an App.

Limitation of getting record information from Apps

When working with Kintone customizations, there are many scenarios where it is necessary to retrieve information of every record in an App. It is important to know what options there are and what limitations exist.

Using the Record List Event (app.record.index.show)

Kintone has a record list event.
This event runs when the record list is displayed, and provides the user with an event object containing information of all of the records in the current record list.

The records that are returned are limited to the records that are displayed on the page. Kintone shows from 20 to 100 records in the record list page (this can be changed with an option listed on the record list page). Therefore, it is only possible to get information of a maximum of 100 records in the event object. This of course becomes an issue in situations where retrieving more than 100 records is necessary.

Using the Get Records API

In the JavaScript code, the Kintone REST API request can be used to run Kintone's Get Records API. By default, this API retrieves up to 100 records, but by setting the limit option in the query parameter, this limit can be raised to a maximum of 500 records. The same issue exists here though - what can be done if there are over 500 records in the App?

How to get all records from an App

The answer to this, is to use the Get Records API recursively, using promises.

Recursive functions are functions that make a call to itself - the Get Records API can be called, and once the number of records that can be retrieved hits its limit, the function can be made to call itself again to retrieve even more records. This will continue until every record has been retrieved from the App.

Promises allow the functions to be called one after the other. While placing the Get Records API in a standard for loop may seem like a good choice, the Get Records API is an asynchronous operation, so the loop tends to end before even the first set of results is returned. Promises wait for the results of the first Get Records API to come back before sending its request for the second Get Records API, and the same for the third, fourth, etc.

Sample Code

The Result

This code will give back information of all records of an App, and display it in the developer console of the browser.
This code can be tested right now by opening the record list of the Kintone App, and copy and pasting the code above into the console.

Finally

This code will come in handy for many types of Kintone customizations. For example, it can be used with Kintone's Custom View (a feature that displays custom HTML on the record list view) to display more than 100 records. Another method of retrieving all records, called the seek method, exists as well. Check out the Get all records (the seek method) tutorial for details.

Was this article helpful?
0 out of 0 found this helpful
Do you have any questions or issues related to this article?
Please share your views with us in the Community forums!