I'm really new into this so sorry if not explained correctly.
-I'm displaying Customers Orders for PC HARDWARE in my sheet, form column "A to F". Each with a generic header. (Comes from Orders SS) -They include Customer Data (Order number, name,tel,deposit,date, etc) and the products/quantity (Comes from product registry SS)
Now in the same sheet- Column "G to I" we insert data refering to each order/product. This data has to be bound to the other. while )Orders may have changes in products sometimes meaning changes in num of rows of the order to. )Fullfilled Orders are not shown anymore
I need the data to stay attached to the corresponding order
Here a Screenshoot of what the Sheet looks like
And this is the current Code
function pruebapedido (){
const cajas = Hoja_RegCaja.getRange(2,1,Hoja_RegCaja.getLastRow(),9).getValues()
const pedidospend2 = Hoja_Regseñas.getRange(2,1,Hoja_Regseñas.getLastRow(),4).getValues()
const Hrespaldo = activaPedidos.getSheetByName('respaldo')
//Get Ordernumbers
let data = Hoja_Regseñas.getRange(2,1,Hoja_Regseñas.getLastRow(),1).getValues().filter(a=>a!='')
const removeDuplicates = arr2d => [...new Set(arr2d.flat())].map(e => [e]);
let Ordenes = removeDuplicates(data)
let array1 = [] //Prodcts
let array2 = [] //Order Data
for (i in Ordenes){
//PRODUCTOS Y CANTIDADES----
array1.push(['Productos','Unid']) //header1
const productos = pedidospend2.filter(a=>a[0]==Ordenes[i])
for (e in productos){array1.push(productos[e].slice(2,4) )}
array1.push(['',''],['',''])
if (productos.length==1){array1.push(['',''],['',''])}
if (productos.length==2){array1.push(['',''])}
//DATOS DE CLIENTE----
array2.push(['N Orden','Datos Cliente','Seña','Fecha'] ) //header2
const nieto2 = cajas.find(a=>a[0].includes(Ordenes[i]))
array2.push(['',nieto2[2],nieto2[8],nieto2[1]],[Ordenes[i][0],nieto2[4],'',''],['',nieto2[5],'',''],['','','',''],['','','',''])
if(productos.length>3){for (a=0;a<productos.length-3;a++){array2.push(['','','','']);}}
}
Hrespaldo.getRange(1,5,array1.length,2).setValues(array1)
Hrespaldo.getRange(1,1,array2.length,4).setValues(array2)
}
Appart from my question, any suggestion to enhance my code will be greatly appreciated!