Calculate and display total record counts

This sample code calculates the total number of records with a given value, and displays the total at the top of the record list page. If the record list has a filter condition, the calculation will take in account of the filter condition.

Sample Image

recordcount.PNG

Sample Code

(function() {
    "use strict";

    var DROPDOWN = 'drop_down'; //field code of dropdown field
    var DROPDOWN_CHOICE1 = 'In progress'; //name of dropdown choice

    // Record List Event
    kintone.events.on('app.record.index.show', function(event) {
        // Gets records based on the current filter of the list
        var query = kintone.app.getQueryCondition();
        if (query === '') {
            query += ' ' + DROPDOWN + ' in ("' + DROPDOWN_CHOICE1 + '")';
        } else {
            query += ' and ' + DROPDOWN + ' in ("' + DROPDOWN_CHOICE1 + '")';
        }
        kintone.api('/k/v1/records', 'GET', {
            app: kintone.app.getId(),
            query: query,
            totalCount: true
        }, function(resp) {
            kintone.app.getHeaderMenuSpaceElement().innerHTML = DROPDOWN_CHOICE1 + ':' + resp.totalCount;
        });
    });
})();

Notes

Refer to the Tutorial page, on how to add scripts to your app.

Was this article helpful?
0 out of 0 found this helpful
Comments
Please sign in to leave a comment.