From f71997d69797f2167bd0d81baa41fa8b9093d868 Mon Sep 17 00:00:00 2001 From: borja Date: Fri, 17 Nov 2023 09:49:58 +0100 Subject: [PATCH] =?UTF-8?q?a=C3=B1ade=20el=20codigo=20que=20identifica=20l?= =?UTF-8?q?os=20nombres=20y=20los=20c=C3=B3digos=20y=20tal?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- importarExcel/solicToName.js | 86 ++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 importarExcel/solicToName.js diff --git a/importarExcel/solicToName.js b/importarExcel/solicToName.js new file mode 100644 index 0000000..7ab7c7b --- /dev/null +++ b/importarExcel/solicToName.js @@ -0,0 +1,86 @@ +// +// CONSTANTS + +const ORIGIN_TABLE_NAME = "BASE DE DATOS"; +const ORIGIN_VIEW_NAME = "Default View"; + +const TARGET_TABLE_NAME = "Solicitantes" +const TARGET_VIEW_NAME = "Default View"; + +const originTable = base.getTableByName(ORIGIN_TABLE_NAME); +const originView = base.getViewByName(originTable, ORIGIN_VIEW_NAME); + +const targetTable = base.getTableByName(TARGET_TABLE_NAME); +const targetView = base.getViewByName(targetTable, TARGET_VIEW_NAME); + +const clientList = {}; + +const originRows = base.getRows(originTable, originView); + +originRows.forEach((row) => { + + const solicitCode = row["Solic"]; + const solicitorName = row["Nom.Solicitante"]; + const clientName = row["Nom.Cl.Final"]; + + const items = { + "solName": new Set(), + "cliName": new Set(), + }; + + items["solName"].add(solicitorName); + items["cliName"].add(clientName); + // + // Si es nuevo, añadir tal cual + if (clientList[solicitCode] === undefined) { + + clientList[solicitCode] = { + solName: items["solName"], + cliName: items["cliName"] + } + } + + // Si es repetido, añadir los nombres al array + if (clientList[solicitCode]) { + + clientList[solicitCode].solName.add(solicitorName); + // console.log(clientList[solicitCode]); + clientList[solicitCode].cliName.add(clientName); + + } + +}); + +Object.keys(clientList).forEach((key) => { + + if (clientList[key].solName.size === 1 && clientList[key].cliName.size === 1) { + const rowData = { + "Code": key, + "Nombre": clientList[key].solName.values().next().value, + "Name": clientList[key].cliName.values().next().value + } + base.addRow(targetTable, rowData); + } else { + + clientList[key].solName.forEach((name) => { + + const rowData = { + "Code": key, + "Nombre": name, + } + base.addRow(targetTable, rowData); + + }); + + clientList[key].cliName.forEach((name) => { + + const rowData = { + "Code": key, + "Name": name, + } + base.addRow(targetTable, rowData); + }) + + } + +})