# Total value on list view changes when I sort records

**URL:** <https://forum.kintone.dev/t/total-value-on-list-view-changes-when-i-sort-records/1709>\
**Category:** General\
**Created:** [July 28, 2026, 6:43am UTC](https://forum.kintone.dev/t/total-value-on-list-view-changes-when-i-sort-records/1709 "2026-07-28T06:43:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![zebra\_taxi](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.kintone.dev/zebra_taxi/32/1006_2.png) [@zebra\_taxi](https://forum.kintone.dev/u/zebra_taxi)\
**Post date:** [July 28, 2026, 6:43am UTC](https://forum.kintone.dev/t/total-value-on-list-view-changes-when-i-sort-records/1709/1 "2026-07-28T06:43:01Z")

</div>

### Question / Problem

I am calculating total of number field and showing it on top of record list. It was working for few days, but now total seems wrong when I add more records. Also, when I change sort order of list, total value changes. I don't understand why sorting can change a total. Any help or advice please!

### Current Situation

I am building a POC for handling sales data. Right now I am making a mock with dummy data. My customization calculates total of `amount` field and displays it at top of the app list view.

It was working okay at first. But recently when I add new records the total does not go up as much as I expect. Sometimes total goes down??? Then I accidentally click header column and sorted the list, and I saw the total value change. When I change asc/desc order of other fields, total number changes.

### App Configuration

I have two number fields calculated to output into `amount` field.  
I use JavaScript customization to calculate total of `amount` field when list view event is triggered.

```javascript
(function() {
  'use strict';

  kintone.events.on('app.record.index.show', function(event) {
    let records = event.records;
    let total = 0;
    records.forEach(function(record) {
      total += Number(record.amount.value);
    });

    let spaceElement = kintone.app.getHeaderMenuSpaceElement();
    spaceElement.innerHTML = 'Total Amount in All Records: ' + total;

    return event;
  });
})();

```

### Error Message

No error messages in console

### Screenshot

You can see total number changing when order is different

 ![customize1](https://canada1.discourse-cdn.com/flex035/uploads/kintone/original/2X/b/b441f082d27c67f0d474fbed9de2cdc3f0d7bf84.png)

 ![customize3](https://canada1.discourse-cdn.com/flex035/uploads/kintone/original/2X/a/a9cda31708b319506818da595d267fa4c0206bce.png)

 ![customize2](https://canada1.discourse-cdn.com/flex035/uploads/kintone/original/2X/a/a7476df70209b70102b187cf7ca6ad11b7069e65.png)

### Desired Outcome

I want total of `amount` to be calculated from the App and be displayed at top of App.  
I don't want total to change when no data is edited. Total `amount `should only change when new data is added, or current data is updated.

---

<div class="post-metadata">

**Author:** ![Chris](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.kintone.dev/chris/32/44_2.png) [@Chris](https://forum.kintone.dev/u/Chris)\
**Post date:** [July 28, 2026, 4:21pm UTC](https://forum.kintone.dev/t/total-value-on-list-view-changes-when-i-sort-records/1709/2 "2026-07-28T16:21:59Z")

</div>

Hello @zebra_taxi

Welcome to the community!

Based on your script, it appears that it is calculating only the records displayed on the current list page because it is using **event.records**. As a result, when you change the sort order, a different set of records may be displayed on the current page, which would explain why the total changes.

To calculate the total across the entire app, you can use the [Get Records REST API](https://kintone.dev/en/docs/kintone/rest-api/records/get-records/)to retrieve all applicable records and calculate the total from the API response instead of using event.records. Please note that a single Get Records request can retrieve up to 500 records, so if your app contains more than 500 records, multiple requests will be required to retrieve all records.

Here are a few additional help pages you can refer to while writing your script:

> **[Get All Records from an App: The Offset Method vs The Seek Method](https://kintone.dev/en/tutorials/development-productivity/get-all-records-from-an-app-offset-vs-seek-method/)**
>
> This article introduces how to retrieve data of all records from a Kintone App, comparing performance with the Offset and Seek Method.

> **[Code Examples For Bulk Record Retrieval](https://kintone.dev/en/tutorials/development-productivity/code-examples-for-bulk-record-retrieval/)**
>
> This article introduces 3 sample codes for bulk retrieving records from a Kintone App.

> **[The Three Methods for Bulk Record Retrieval](https://kintone.dev/en/tutorials/development-productivity/the-three-methods-for-bulk-record-retrieval/)**
>
> This article introduces three methods for bulk record retrieval from a Kintone App.

I hope this helps.

---

<div class="post-metadata">

**Author:** ![zebra\_taxi](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.kintone.dev/zebra_taxi/32/1006_2.png) [@zebra\_taxi](https://forum.kintone.dev/u/zebra_taxi)\
**Post date:** [July 29, 2026, 2:21am UTC](https://forum.kintone.dev/t/total-value-on-list-view-changes-when-i-sort-records/1709/3 "2026-07-29T02:21:27Z")

</div>

Hi Chris, thanks for you reply!

Yes I am using event object to get record data. I did not realize 100 records was the max amount of data in event object. I have more than 100 records in kintone app 🫣

Is there any way to increase max records stored in event object?

Or should I ignore event object and go ahead to use REST API to get all record data?

---

<div class="post-metadata">

**Author:** ![Chris](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.kintone.dev/chris/32/44_2.png) [@Chris](https://forum.kintone.dev/u/Chris)\
**Post date:** [July 29, 2026, 3:23pm UTC](https://forum.kintone.dev/t/total-value-on-list-view-changes-when-i-sort-records/1709/4 "2026-07-29T15:23:47Z")

</div>

Hello @zebra_taxi

According to the [Kintone documentation (Noted on the Limitations)](https://kintone.dev/en/tutorials/custom-view/display-list-of-records-in-a-custom-view/), the maximum number of records that can be stored in event.records is 100, and this limit cannot be increased. If you navigate to another page in the record list, the Event Object is updated with the records from that page.

Thus, if you need to calculate the total across more than 100 records, I would recommend using the Get Records REST API instead of event.records. The Get Records API can retrieve up to 500 records per request, and you can make multiple requests if your app contains more than 500 records.

So in your case, since your app contains more than 100 records, using the REST API would be the recommended approach to ensure the total is calculated correctly regardless of the current page or sort order.

---

<div class="post-metadata">

**Author:** ![zebra\_taxi](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.kintone.dev/zebra_taxi/32/1006_2.png) [@zebra\_taxi](https://forum.kintone.dev/u/zebra_taxi)\
**Post date:** [July 30, 2026, 5:11am UTC](https://forum.kintone.dev/t/total-value-on-list-view-changes-when-i-sort-records/1709/5 "2026-07-30T05:11:18Z")

</div>

Thank you for making it clear to use REST API and not event object for my scenario.

I checked [The Seek Method](https://kintone.dev/en/tutorials/development-productivity/get-all-records-from-an-app-offset-vs-seek-method/) and applied it to my code.

My code works OK now. Total doesn't change when fields reorder.  
I also tested with over 500 records. The total is calculated OK!

 ![total](https://canada1.discourse-cdn.com/flex035/uploads/kintone/original/2X/d/dc546f064557acbf0c5ae8a0857428c3037ee401.png)

Here is updated code for reference:

```javascript
(function() {
  'use strict';

  function getAllRecords(lastRecordId, records) {
    //Pass on empty array for first call
    records = records || [];
    //Add no record related query for first call
    let query = lastRecordId ? '$id > ' + lastRecordId : '';
    
    query += ' order by $id asc limit 500';

    let params = {
      app: kintone.app.getId(),
      query: query
    };

    return kintone.api('/k/v1/records', 'GET', params).then(function(resp) {
      records = records.concat(resp.records);
      if (resp.records.length === 500) {
        return getAllRecords(resp.records[resp.records.length - 1].$id.value, records);
      }
      return records;
    });
  }

  kintone.events.on('app.record.index.show', function(event) {
    getAllRecords().then(function(records) {
      let total = 0;
      records.forEach(function(record) {
        total += Number(record.amount.value);
      });

      let spaceElement = kintone.app.getHeaderMenuSpaceElement();
      spaceElement.innerHTML = 'Total Amount in All Records: ' + total;
    });

    return event;
  });
})();

```

Thank you, my issue solved now 😁
