Kintone.api('/k/v1/records', 'GET', params) not getting the records

I am trying to use the kintone.api() method in my JavaScript to get records from a Kintone App.

However, it is not getting the App's records. The response.records.length is 0 even though the App has records.

Is there any problem with the query string?

kintone.events.on("app.record.create.show", function (event) {
  let record = event.record;
  let query = 'proforma_number like "S"';
  let params = { app: 117, query: query };

  return kintone.api("/k/v1/records", "GET", params).then(
    function (response) {
      console.log("response", response);

      let maxNum = "";
      const yyyy = new Date().getFullYear().toString();

      console.log("response.records.length", response.records.length);

      if (response.records.length) {
        let pattern = `S${yyyy}\\d\\d\\d`;
        let regexp = new RegExp(pattern);

        // loop through the response array to find the highest proforma number
        for (let i = 0; i < response.records.length; i++) {
          if (response.records[i]["proforma_number"]["value"]) {
            if (regexp.test(response.records[i]["proforma_number"]["value"])) {
              if (!maxNum) {
                maxNum = response.records[i]["proforma_number"]["value"];
              } else if (
                response.records[i]["proforma_number"]["value"] > maxNum
              ) {
                maxNum = response.records[i]["proforma_number"]["value"];
              }
            }
          }
        }

        if (maxNum == "") maxNum = `S${yyyy}000`;
      } else maxNum = `S${yyyy}000`;

      let last3Plus1 = parseInt(maxNum.slice(-3)) + 1;
      let first5 = maxNum.slice(0, 5);

      let nextProforma = `${first5}${last3Plus1.toString().padStart(3, 0)}`;
      record.proforma_number.value = nextProforma;
      return event;
    },
    function (error) {
      console.log(error);
      return event;
    }
  );

  return event;
});

Hi @annaylee,

I checked the code you provided, and it uses the "like" operator in the query parameter. In the process of retrieving records using the "GET" method of the "kintone" API, when utilizing the "like" or "not like" operators in the query parameter, searches are performed based on [containing/not containing] the specified keywords.

When narrowing down records using the "kintone" REST API, the following search specifications apply:

If the keyword consists of alphanumeric characters, searches can be conducted word-by-word. For example, in the case of records containing "test123," the keyword "test123" is treated as a single word. You can perform searches using exact matches with the keyword "test123." As a result, the following keywords would not lead to successful searches:

・"test"

・"123"

Based on the above information, if you have a query like 'proforma_number like "S,"' you will not be able to retrieve information such as "S12345."

Please note that if you include characters like "-" between alphanumeric characters, they will be treated as multiple words. Consequently, modifying the data to include characters like "S-12345" would allow for successful data retrieval.

When Searching with Alphanumeric Characters https://get.kintone.help/k/en/id/040689.html#search_search_details_6020

When Searching for a String That Consists of Only Alphanumeric Characters

Could you kindly explain which data you are experiencing issues with retrieving?

1 Like

A post was split to a new topic: "Private" vs "Public" App?