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);