Get the return values after filtering.

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?

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

Hello Yuzo Arai,

Help me this one please!

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
(Only in Japanese)

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

Hopefully, this helps.

Hello Sean Tachibana, 

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.

 

your code:

How about the value in next page? 

 

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

 

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

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

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. 

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

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

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.

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.

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

I hope this helps

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.