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;
});