Avatar

Kintone Update all Records in Index

James Coleman

Hey, I was wondering if there was any way to update all records in the index page. Or if that is not possible, any other way to bulk update the records inside the app. Any help or comments is appreciated.

 

Sample code:

kintone.events.on("app.record.index.show", function(event) {
var records = event.records;
for (var i = 0; i < records.length; i++) {
var record = records[i];
record['test'].value = "Some Value";
}

return event;


});

Follow 3 followers
0

3 comments

Avatar
Junko Werner 1 vote
Hi James,
 
After an event (app.record.index.show) triggered to display the record list page, the value cannot be updated in the notification processing so that with your sample quote, the value cannot be updated.

▼ Events when the record detail screen is displayed
*Please see ”What you can do with the event object” 

Therefore, if you would like to update a record in app.record.index.show, you must use the batch record update "PUT" method.

Please note that record bulk update "PUT" can update up to 100 records in a single run.

Therefore, if you want to update more than 100 records in bulk, you might want to write a coding like recursion processing. If it is difficult for you to write such, I would suggest using the following plug-in.

▼ JOYZO Bulk Update
1
Comment actions Permalink
Avatar
James Coleman 1 vote

I ended up getting it work thanks to Junko's tip on using the "PUT" method. We tried exporting the files to a CSV and modifying each time but that would be to time consuming for how many records we have to update. This code updates each value every time the index page is shown and more complicated equations can be used in this simple example.

 

My Code:

kintone.events.on('app.record.index.show', function (event) {

  var records = event.records;

  for(var i = 0; i < records.length; i++) {

    var record = records[i];

    var tempID = record.<record number/ID>.value;  //To get ID in a field, just use a record number field and it is autofilled

    var body = {

         app: kintone.app.getID(),

         id: tempID,

        record:  {  "fieldname":  { "value": <Enter updated value here>  },

                        "fieldname2": { "value": <Enter 2nd value to be updated> }

        };

       kintone.api('/k/v1/record', 'PUT', body);

     }

 });

           

  

1
Comment actions Permalink