// Finds all the names attributed to the same Solicitor code // CONSTANTS const ORIGIN_TABLE_NAME = "raw_data"; 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); }) } })