From d2f271e3cd846570cf006b826c0d81be5c2d8a5b Mon Sep 17 00:00:00 2001 From: Mouriya Date: Mon, 17 Jun 2024 15:22:10 +0900 Subject: [PATCH] =?UTF-8?q?=E3=82=A8=E3=83=B3=E3=83=88=E3=83=AA=E3=83=BC?= =?UTF-8?q?=E3=82=92=E8=BF=BD=E5=8A=A0=E3=81=99=E3=82=8B=E3=81=A8=E3=81=8D?= =?UTF-8?q?=E3=81=AB=E3=83=87=E3=83=BC=E3=82=BF=E3=82=92=E7=B5=B1=E5=90=88?= =?UTF-8?q?=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/actions/data-mapping.ts | 41 ++++++++----------- 1 file changed, 16 insertions(+), 25 deletions(-) diff --git a/plugin/kintone-addins/src/actions/data-mapping.ts b/plugin/kintone-addins/src/actions/data-mapping.ts index 2b2ac10..ec08137 100644 --- a/plugin/kintone-addins/src/actions/data-mapping.ts +++ b/plugin/kintone-addins/src/actions/data-mapping.ts @@ -84,41 +84,32 @@ export class DataMappingAction implements IAction { this.actionProps = prop.actionProps; this.dataMappingProps = prop.ActionValue as Props; console.log(prop.ActionValue); - + // this.initTypedActionProps(); let result = { canNext: true, result: "", } as IActionResult; try { - for (const item of this.dataMappingProps.dataMapping) { - if (item.from.objectType === "variable") { - if ( + const record = this.dataMappingProps.dataMapping + .filter( + (item) => + item.from.objectType === "variable" && item.from.name.name && item.to.app && item.to.fields && item.to.fields.length > 0 - ) { - const value = getValueByPath( - context.variables, - item.from.name.name - ); - if (value) { - await kintone.api( - kintone.api.url("/k/v1/record.json", true), - "POST", - { - app: item.to.app.id, - record: { - [item.to.fields[0].code]: { - value: value, - }, - }, - } - ); - } - } - } + ) + .reduce((accumulator, item) => { + return {...accumulator, [item.to.fields[0].code]: { + value: getValueByPath(context.variables, item.from.name.name), + }}; + }, {}); + if (record && Object.keys(record).length > 0) { + await kintone.api(kintone.api.url("/k/v1/record.json", true), "POST", { + app: this.dataMappingProps.sources.app.id, + record: record, + }); } } catch (error) { console.error("DataMappingAction error", error);