お世話になっております。
JS初心者ですて。
【アプリAにある添付ファイル】を【アプリBにあるサブテーブル内にある添付ファイル】にコピーしたいと思っております。
下記の記事を参考に試してみたのですが、上手くいきませんでした。
現象としまして、
1.レコード作成時[ルックアップ]フィールドが表示されない
【現在のコード】
(function() {
"use strict";
var table = 'tesテーブル'; //サブテーブルのフィールドコード
var lookupField = '運営会社';
var lookupIdField = '運営会社';
var originAttachmentsField = '手数料CP_画像';
var copyAttachmentsField = '添付ファイル1';
kintone.events.on([
'app.record.detail.show',
'app.record.create.show',
'app.record.edit.show',
], function(event){
kintone.app.record.setFieldShown(lookupIdField, false);
event.record[table].value.forEach(function(row){
row.value[copyAttachmentsField].disabled = true;
});
return event;
});
kintone.events.on([
'app.record.create.submit.success',
'app.record.edit.submit.success',
], function(event){
var client = new KintoneRestAPIClient();
return kintone.Promise.all(event.record[table].value.map(function(row){
if(!row.value[lookupIdField].value) return [];
return client.record.getRecord({
app: kintone.app.getLookupTargetAppId(lookupField),
id: row.value[lookupIdField].value
}).then(function(originRecord){
return kintone.Promise.all(originRecord.record[originAttachmentsField].value.map(function(originFileInfomation){
return client.file.downloadFile({
fileKey: originFileInfomation.fileKey
}).then(function(fileData){
return {
file: {
name: originFileInfomation.name,
data: new Blob([fileData], {type: originFileInfomation.contentType})
}
};
});
}));
}).then(function(files){
return kintone.Promise.all(files.map(function(files){
return client.file.uploadFile(files);
}));
});
})).then(function(copyFileInfomationsChunks){
return client.record.updateRecord({
app: event.appId,
id: event.recordId,
record: {
[table]: {
value: event.record[table].value.map(function(row, index){
return {
value: {
...row.value,
[copyAttachmentsField]: {
value: copyFileInfomationsChunks[index]
}
}
}
})
}
}
});
});
});
})();
【アプリ画像】
ご教示の程よろしくお願いいたします。