社員アプリ(社員コード、社員名、印鑑)を見積書アプリでルックアップ(社員コードを選択)社員アプリの印鑑(添付ファイル)フィールドを見積書アプリにの担当印鑑にコピーしようとしたらエラーなり、誰か助言の程、お願い致します。
社員アプリ
・社員コード
・社員名
・印鑑
見積書アプリ(今回試みている場所)
・担当コード(ルックアップ)
・担当ID(担当コードからコピーされる)
・担当者名(ルックアップからコピーされる)
・担当印鑑(今回の困りごと)
(function() {
"use strict";
var lookupField = '担当コード';
var lookupIdField = '担当ID';
var originAttachmentsField = '印鑑';
var copyAttachmentsField = '担当印鑑';
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[copyAttachmentsField].disabled = true;
return event;
});
kintone.events.on([
'app.record.create.submit.success',
'app.record.edit.submit.success',
], function(event){
if(!event.record[lookupIdField].value) return;
var client = new KintoneRestAPIClient();
return client.record.getRecord({
app: kintone.app.getLookupTargetAppId(lookupField),
id: event.record[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(file){
return client.file.uploadFile(file);
}));
}).then(function(copyFileInfomations){
return client.record.updateRecord({
app: event.appId,
id: event.recordId,
record: {
[copyAttachmentsField]: {
value: copyFileInfomations
}
}
});
}).then(function (){
return event;
});
});
})();