Situtation
Hi, I am trying to catch the event change on a Dropdown and then get the value from the reference App.
After that, I need to update the table row with the API call’s results.
Script
This is my code below:
const tableStaff = 'カット対応人数';
const appStaff = 3516;
kintone.events.on('app.record.create.change.店舗', function (event) {
let record = event.record;
getRecords('店舗 = "' + record['店舗']['value'] + '"', appStaff).then(result => {
event.record[tableStaff].value = [];
result.records.forEach(function (staff) {
let staffData = {
id: null,
value: {
"スタッフ": {
type: 'SINGLE_LINE_TEXT',
value: staff['スタッフ']['value']
},
"人数": {
type: 'NUMBER',
value: 0
},
}
};
event.record[tableStaff].value.push(staffData);
});
console.log(event);
return event;
});
});
Error
My Problem is this function always returns the event before getRecords()
completes.
I’ve tried to use Async/await on the getRecords()
function. Usually, it works, but this time, I got the following error:
Uncaught Error: app.record.create.change.店舗 is not allowed to return "Thenable" object.
I do not know why I got this error.
Could you explain what happens when I use Async/Await in a Kintone customization?