How to Speed up My Kintone Customization?

How to Speed up My Kintone Customization?

Question / Problem

Hello, I have a simple JavaScript customization that is running slow.
How can I speed it up?

Current Situation

I have 3 Kintone Apps linked by the company_ID field.

  • App A stores the company's name using the Company_Name_Hangul field.
  • App B stores the person's name using the name field.
  • App C - I want to do something in this app.

The JavaScript customization is running on App C.

I am using the async/await code from the 目指せ!JavaScriptカスタマイズ中級者(2) 〜Promiseのかわりにasync/await編〜 article.

Customization Flow

  1. From App C, it will fetch records from App A.
  2. It will then extract the company_ID from each record
  3. It will pass the company_ID as a parameter to App B to get the person's name associated with the company.

Code / Attempts

var createRows = async function (rows, recordEnd, records) {
  for (var i = 0; i < recordEnd; i++) {
    var company = records[i].company_ID.value;
    var name = records[i].name.value;
    var Company_Name_Hangul = '';
    var Headquarters_Address = '';
    var Zip_Code = '';
    var body = {
      "app": 17,
      "query": "Company_ID=" + company + " order by $id asc limit 100 offset 0",
      "fields": ["Headquarters_Address", "Zip_Code", "Company_Name_Hangul"]
    };
    const resp1 = await kintone.api('/k/v1/records', 'GET', body);

    var addr1 = Headquarters_Address.split("\r\n")[0];
    var addr2 = Headquarters_Address.split("\r\n")[1];
    rows.push([{ content: addr1, styles: { minCellHeight: 1, fontSize: 8.5, cellPadding: 1 } }])
    rows.push([{ content: addr2, styles: { minCellHeight: 1, fontSize: 8.5, cellPadding: 1 } }])
    rows.push([{ content: Company_Name_Hangul, styles: { minCellHeight: 1, fontSize: 10.5, cellPadding: 1 } }])
    rows.push([{ content: name, styles: { minCellHeight: 1, fontSize: 12.5, cellPadding: 0, halign: 'right', fontStyle: 'bold' } }])
    rows.push([{ content: Zip_Code, styles: { minCellHeight: 1, fontSize: 10.5, cellPadding: 1, halign: 'right', fontStyle: 'bold' } }])
    rows.push([{ content: 'empty', styles: { minCellHeight: 1, fontSize: 10.5, cellPadding: 1 } }])
  }

  var event1 = generatePDF(rows);

  return rows;
}

kintone.events.on(events, function (event) {

  button.addEventListener('click', event => {

    var subject = ''
    var contents = ''
    fetchRecords(20).then(function (records) {
      console.log(records);
      var cnt = records.length

      //insert
      var label = ''
      const recordEnd = cnt;
      var row = [];
      row = createRows(row, recordEnd, records);

      console.log(label);
    });
  });

  header.appendChild(button);

  return event;
});

Referenced Resources

Hello @H_Nar ,

At times, users may experience this issue when utilizing the Get Records "GET" ('/k/v1/records') method.

As indicated in the following documentation (Japanese version), performance can be improved by specifying the required field code within the fields parameter. This may be especially useful if the Get Records "GET" method is demonstrating slow performance.

However, given that you have already specified the fields parameter, the issue may stem from a different cause.

As you may be aware, the processing time for APIs can be significantly influenced by several factors such as the number of fields and records, permissions within an app, and network conditions. Therefore, pinpointing the exact cause can be challenging.

At this point, I would recommend a few steps to investigate further:

  • Create a new app and run the same process to determine if the issue recurs.
  • If you have a very large number of records, test with an app that has fewer records.
  • You seem to have the generatePDF function running in a loop within the createRows function, this could be a potential source of delay, it might be worthwhile to check the execution time here.

I hope these steps might assist you in diagnosing the issue.

The following page might be useful, too:

1 Like