About adding subtable data in the dropdown

In the dropdown, the data related to the specified value is displayed in the sub-table.

Problem 1: Even if the dropdown value is changed, it is not reflected in the subtable.

Problem 2: I don’t know how to initialize the subtable.

Could anyone please teach me?

(function() {
“use strict”;

kintone.events.on([‘app.record.create.show’,‘app.record.edit.show’,‘app.record.create.change.User’,‘app.record.edit.change.User’,‘app.record.create.change.Charge’, ‘app.record.edit.change.Charge’], function(e){
var record = e.record;
var orderdatas = {};
var tt = 0;
var Name = record[‘Charge’].value
var body = {
‘app’: 127,
‘query’: ‘Charge = "’ + Name + ‘"’
}

return kintone.api(kintone.api.url(‘/k/v1/records’, true), ‘GET’, body).then(function(resp) {
resp.records.forEach(function(record) {
tt = tt + 1;
var Address1 = record[“Address1”].value;
var Address2 = record[“Address2”].value;

orderdatas[tt] = {
“Address11”: Address1,
“Address12”: Address2
}
//window.alert(1);
});
return setData();
});

function setData() {
var TableB = record[‘User’].value;

var index = TableB.length - 1;
for (var i = 0; i <= index; i++) {
TableB.splice(0, 1);
}
for (var key in orderdatas) {
TableB.push({
value: {
“Address11”: {value: orderdatas[key][“Address11”], type: “SINGLE_LINE_TEXT”},
“Address12”: {value: orderdatas[key][“Address12”], type: “SINGLE_LINE_TEXT”}
}
});
}
return e;
}
});
})();

Hello TS44,

Answer to your Problem 1:
It seems you are using Promises in the change event, but unfortunately, you can’t use it in the change event.

The following page lists the JavaScript event handlers and Kintone methods that support Promises:

Kintone Developer Program - Using Promises over Synchronous XHR - Overview of Kintone JavaScript APIs and Promises
https://developer.kintone.io/hc/en-us/articles/115007823527-Using-Promises-over-Synchronous-XHR

So it would be best to stop using the synchronous process for GET API in the change events. And use kintone.app.record.get()
and kintone.app.record.set() within the GET process that was executed asynchronously.

Answer to your Problem 2:
You need to set [] in the value of a table.

I hope this answers your questions.