Numbering Tables

This sample code automatically adds row numbers to tables every time the record is saved.

Sample Image

numbertables.gif

Sample Code

(function() {
    "use strict";

    var NUMBERFIELD = "numbering"; //field code of number field in the table
    var TABLEFIELD = "mytable"; //field code of the table

    var events = [
        'app.record.create.submit',
        'app.record.edit.submit'
    ];
    kintone.events.on(events, function(event) {
        var record = event.record;

        //auto-number the table rows
        var count = record[TABLEFIELD].value.length;
        for (var i = 0; i < count; i++) {
            record.Table.value[i].value[NUMBERFIELD].value = i + 1;
        }

        return event;
    });
})();

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.