How to use kintone.api() to select only items that match a specified pattern?

This is for the Detail Create page.

I want to use kintone.api() to select only customer quotes that match “SQ-22xxxx” pattern. The ‘xxxx’ represents 4 digits. How to correctly construct the query?

kintone.events.on("app.record.create.show", function (event) {
  let record = event.record;

  let query = "";
  params = { app: 91, query: query };

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

Your kind assistance will be greatly appreciated.

Hi annaylee,

The same specifications as the native feature apply when searching for records with the “kintone” REST API.
So, as described in the help article below, when searching by alphanumeric characters, searches are performed on a word-by-word basis, so searches cannot be performed using “SQ-22”.

Searching in Alphanumeric Characters - Data Searching

There is also no search method that specifies a wildcard (the xxxx portion of “SQ-22xxxx”).

In the form “SQ-22xxxx”, after extracting the records that contain “SQ,” from the retrieved records, “SQ-22xxxx” must be extracted by the process on the page you have sent us.

Therefore, the modifications would be as follows.

//[Modified]: specify filter by SQ.
let query = "quotes like \"SQ\"";
params = { app: 91, query: query };
kintone.api('/k/v1/records', 'GET', params).then(function (response) {
  if (response.records.length) {
    console.log(response.records);
    //[Modified]: extract records matching the format "SQ-22xxxx".
    var filter = response.records.filter(function (record) {
      return record.quotes.value.match("SQ-22");
    });
    console.log(filter);
  }
  return event;
}, function (error) {
  console.log(error);
});

(console.log(response.records); to display the retrieved records
console.log(filter); to extract and display records that match the “SQ-22xxxx” format.)

Hopefully, this helps.