Hi, I’m trying to set records into a table and I’m using event catch field on change of Kintone.
I want to check all fields when it changes in the table or be set from JavaScript is validated or not and in some cases when events is raised, some fields of table still have no value.
So I want to waiting when all fields in table have value and I’m trying to ignore event went it be set from javascript or wait for all events is done.
Using Promises or Async/Await to create an asynchronous process should resolve your issue.
The following is an example of obtaining three records and totaling their value upon saving a record:
Promises Example:
kintone.events.on(['app.record.create.submit', 'app.record.edit.submit'], (event) => {
return kintone.api('/k/v1/record', 'GET', params1)
.then((resp1) => {
event.record.Total.value += Number(resp1.record.Subtotal.value);
// 2nd API Process
return kintone.api('/k/v1/record', 'GET', params2);
// Using .then() to wait for the process
}).then((resp2) => {
event.record.Total.value += Number(resp2.record.Subtotal.value);
// 3rd AP Process
return kintone.api('/k/v1/record', 'GET', params3);
// Using .then() to wait for the process
}).then((resp3) => {
event.record.Total.value += Number(resp3.record.Subtotal.value);
return event;
}).catch((e) => {
// In case of API error
alert(e.message);
return event;
});
});