# Get the return values after filtering.

**URL:** <https://forum.kintone.dev/t/get-the-return-values-after-filtering/362>\
**Category:** General\
**Created:** [November 11, 2020, 6:28am UTC](https://forum.kintone.dev/t/get-the-return-values-after-filtering/362 "2020-11-11T06:28:49Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![legacy\_user](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.kintone.dev/legacy_user/32/25_2.png) [@legacy\_user](https://forum.kintone.dev/u/legacy_user)\
**Post date:** [November 11, 2020, 6:28am UTC](https://forum.kintone.dev/t/get-the-return-values-after-filtering/362/1 "2020-11-11T06:28:49Z")

</div>

i have a lot of Views, For each view after the filter, I want to get its value, seemingly use a query to query, but I don’t know how to use it yet. Can you make samples for me?

![](https://developer.kintone.io/hc/user_images/BFhKtJlc93d7bCK1C8yxQA.png)

I have a code, but it always returns all records, regardless of whether or not filtered or otherwise. (return value does not change)

---

<div class="post-metadata">

**Author:** ![legacy\_user](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.kintone.dev/legacy_user/32/25_2.png) [@legacy\_user](https://forum.kintone.dev/u/legacy_user)\
**Post date:** [November 11, 2020, 6:29am UTC](https://forum.kintone.dev/t/get-the-return-values-after-filtering/362/2 "2020-11-11T06:29:47Z")

</div>

Hello Yuzo Arai,

Help me this one please!

---

<div class="post-metadata">

**Author:** ![legacy\_user](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.kintone.dev/legacy_user/32/25_2.png) [@legacy\_user](https://forum.kintone.dev/u/legacy_user)\
**Post date:** [November 13, 2020, 1:45am UTC](https://forum.kintone.dev/t/get-the-return-values-after-filtering/362/3 "2020-11-13T01:45:03Z")

</div>

Hello NDC,

I was able to get the value using the code below:

```
(function () {
"use strict";
kintone.events.on(['app.record.index.show'], function (event){
kintone.app.getHeaderMenuSpaceElement().innerHTML = 'sum total:' + event.records.reduce(function(previousValue, record){
return previousValue + Number(record.subtotal.value);
}, 0).toLocaleString();
return event;
});
})();

```

[https://developer.cybozu.io/hc/ja/community/posts/360001961103-kintone-%E3%83%AC%E3%82%B3%E3%83%BC%E3%83%89%E4%B8%80%E8%A6%A7%E7%94%BB%E9%9D%A2-%E9%9B%86%E8%A8%88%E3%81%AB%E3%81%A4%E3%81%84%E3%81%A6](https://developer.cybozu.io/hc/ja/community/posts/360001961103-kintone-%E3%83%AC%E3%82%B3%E3%83%BC%E3%83%89%E4%B8%80%E8%A6%A7%E7%94%BB%E9%9D%A2-%E9%9B%86%E8%A8%88%E3%81%AB%E3%81%A4%E3%81%84%E3%81%A6)  
(Only in Japanese)

Please note that the value was displayed only in the “list view” and not in the “calendar view.”

Hopefully, this helps.

---

<div class="post-metadata">

**Author:** ![legacy\_user](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.kintone.dev/legacy_user/32/25_2.png) [@legacy\_user](https://forum.kintone.dev/u/legacy_user)\
**Post date:** [November 13, 2020, 2:17am UTC](https://forum.kintone.dev/t/get-the-return-values-after-filtering/362/4 "2020-11-13T02:17:09Z")

</div>

Hello Sean Tachibana,&nbsp;

Thank you very much for answering me, but the problem I ask is, the return value it just accumulates on page 1 (meaning it only adds 20 records). while my data currently has 198 records divided into multiple pages, the records after it are not added.

–IMPORTANT

For each view, I just want to sum the values on that view, not the total value of the app.

&nbsp;

your code:

How about the value in next page?&nbsp;

&nbsp;

Do you understand what i mean? maybe my english not very well.

&nbsp;

---

<div class="post-metadata">

**Author:** ![legacy\_user](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.kintone.dev/legacy_user/32/25_2.png) [@legacy\_user](https://forum.kintone.dev/u/legacy_user)\
**Post date:** [November 14, 2020, 5:53pm UTC](https://forum.kintone.dev/t/get-the-return-values-after-filtering/362/5 "2020-11-14T17:53:38Z")

</div>

Hi NDC,

My apologies for the misunderstanding. It seems like the query only specifies an offset and limit; all queries are fetched.

If you specify the same value in “query,” you can get records according to the list.  
You can also specify the criteria for refining the list directly, but since the process is created on the list screen, you can use  
the following functions to process it.

Get Record List Query (with order by, limit, offset):  
[https://developer.kintone.io/hc/en-us/articles/213148937-Get-Record-List](https://developer.kintone.io/hc/en-us/articles/213148937-Get-Record-List)

Could you try this and see if it works for you?  
Hopefully, it helps.

---

<div class="post-metadata">

**Author:** ![legacy\_user](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.kintone.dev/legacy_user/32/25_2.png) [@legacy\_user](https://forum.kintone.dev/u/legacy_user)\
**Post date:** [November 16, 2020, 1:28am UTC](https://forum.kintone.dev/t/get-the-return-values-after-filtering/362/6 "2020-11-16T01:28:27Z")

</div>

Hello Sean Tachibana,

I did it but max it out is limited to 100records (20-40-60-80-100 in paging selection), so I can’t count the remaining records on the next page.&nbsp;

In this case, I can filter out 200,300 and even more under different conditions.

![](https://developer.kintone.io/hc/user_images/XGhv-PHW8AA3cfmUAcGtYg.png)

![](https://developer.kintone.io/hc/user_images/ViDC2qzZoyb4qI-j10-PHw.png)

---

<div class="post-metadata">

**Author:** ![legacy\_user](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.kintone.dev/legacy_user/32/25_2.png) [@legacy\_user](https://forum.kintone.dev/u/legacy_user)\
**Post date:** [November 16, 2020, 7:32pm UTC](https://forum.kintone.dev/t/get-the-return-values-after-filtering/362/7 "2020-11-16T19:32:48Z")

</div>

Hi NDC,

Since the above code does not count records on the different pages, you should consider using REST API to obtain record info and output the sum.  
Just to mention, you need to specify the limit in API (like you did in the original script), or else you could only get 100 records. Although even if you specify the limit, the max is 500, so if there’s more than that, you need to loop the process.

Kintone Developer Program - Get Records  
[https://developer.kintone.io/hc/en-us/articles/360019245194-Get-Records](https://developer.kintone.io/hc/en-us/articles/360019245194-Get-Records)

Found this example, please use it for you reference:

```
(function() {
"use strict";
var getRecords = function(app, tmpRecords){
var limit = 500;
var tmpRecords = tmpRecords || [];
return kintone.api(kintone.api.url('/k/v1/records', true), 'GET', {
app: app,
query: 'limit ' + limit +' offset ' + tmpRecords.length
}).then(function(response){
tmpRecords = tmpRecords.concat(response.records);
return response.records.length === limit ? getRecords(app, tmpRecords) : tmpRecords;
});
}
kintone.events.on('app.record.index.show', function(event){
getRecords(kintone.app.getId()).then(function(records){
kintone.app.getHeaderMenuSpaceElement().innerHTML = 'Total:' + records.reduce(function(previousValue, record){
return previousValue + Number(record.Subtotal.value);
}, 0).toLocaleString();
});
});
})();

```

I hope this helps.

---

<div class="post-metadata">

**Author:** ![legacy\_user](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.kintone.dev/legacy_user/32/25_2.png) [@legacy\_user](https://forum.kintone.dev/u/legacy_user)\
**Post date:** [November 17, 2020, 5:35am UTC](https://forum.kintone.dev/t/get-the-return-values-after-filtering/362/8 "2020-11-17T05:35:53Z")

</div>

Hello Yuzo Arai,

I tried refining the list again, but api doesn’t seem to change value after filtering the data. because the two data after filtering the list, the output was different. but the API gives the same result. HOW can I handle them? Or should stop.

![](https://developer.kintone.io/hc/user_images/n1GuFSc6P8ZVq38qHDf80Q.png)

---

<div class="post-metadata">

**Author:** ![legacy\_user](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.kintone.dev/legacy_user/32/25_2.png) [@legacy\_user](https://forum.kintone.dev/u/legacy_user)\
**Post date:** [November 17, 2020, 6:08pm UTC](https://forum.kintone.dev/t/get-the-return-values-after-filtering/362/9 "2020-11-17T18:08:02Z")

</div>

Hi NDC,

You just need to tweak the query part in the script.  
In your case, I just added ‘kintone.app.getQueryCondition()’,  
which retrieves the record list filter conditions as a query string.

```
(function() {
"use strict";
var getRecords = function(app, tmpRecords) {
var limit = 500;
var tmpRecords = tmpRecords || [];
return kintone.api(kintone.api.url('/k/v1/records', true), 'GET', {
app: app,
query: kintone.app.getQueryCondition() +'limit ' + limit +' offset ' + tmpRecords.length
}).then(function(response){
tmpRecords = tmpRecords.concat(response.records);
return response.records.length === limit ? getRecords(app, tmpRecords) : tmpRecords;
});
}
kintone.events.on('app.record.index.show', function(event){
getRecords(kintone.app.getId()).then(function(records){
kintone.app.getHeaderMenuSpaceElement().innerHTML = 'Total:' + records.reduce(function(previousValue, record){
return previousValue + Number(record.Calculated.value);
}, 0).toLocaleString();
});
});
})();

```

Kintone Developer Program - Get Record List - Get Record List Query  
[https://developer.kintone.io/hc/en-us/articles/213148937-Get-Record-List#getQueryCondition](https://developer.kintone.io/hc/en-us/articles/213148937-Get-Record-List#getQueryCondition)

I hope this helps

---

<div class="post-metadata">

**Author:** ![legacy\_user](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.kintone.dev/legacy_user/32/25_2.png) [@legacy\_user](https://forum.kintone.dev/u/legacy_user)\
**Post date:** [November 18, 2020, 12:59am UTC](https://forum.kintone.dev/t/get-the-return-values-after-filtering/362/10 "2020-11-18T00:59:20Z")

</div>

Hello Yuzo Arai,

Thank you so much for your help, this code seems to have answered my question after so many days of hard work.

There is a problem I will ask again later.
