confía en que eres bueno. Estoy trabajando en un proyecto en el que envié datos de un apk a una hoja de Google. El caso es que envié los datos completos a una hoja y también envío una especie de datos transpuestos a otras hojas, todas con ID personalizados .
Ejemplo aquí:
En Test_Sheet: ID Region Place Staff thing1 thing2 thing3 thing4 thing5
En la hoja test2:
ID thing1
ID thing2
ID thing3
ID thing4
thing5 ID
Todo funciona bien, pero mi problema es que cuando solo tengo menos elementos, la identificación seguirá estando en la hoja test2 como si todos los elementos estuvieran presentes.
ID thing1
ID thing2
ID thing3
ID
ID
Aquí está el código:
function doPost(e) { var ss = SpreadsheetApp.openById('XXXXXXXXXXXXXXXXXXX'); var sh = ss.getSheetByName('Test_Sheet'); var sh2 = ss.getSheetByName('test2') //custom ID var scriptProperties = PropertiesService.getScriptProperties(); var counter = scriptProperties.getProperty('counter') || 0; var formatDate = Utilities.formatDate(new Date(), "GMT+8", "ddMMyy"); var zero = (counter < 10) ? '0' : ''; var ID = "T" + formatDate + zero + counter++; if (counter > 99) counter = 0; scriptProperties.setProperty('counter', counter); \\send from apk var region = e.parameter.region; var place = e.parameter.place; var staff = e.parameter.staff; var thing1= e.parameter.thing1; var thing2= e.parameter.thing2; var thing3= e.parameter.thing3; var thing4= e.parameter.thing4; var thing5= e.parameter.thing5; \\Test_Sheet sh.appendRow([ID, region, place, staff, thing1, thing2, thing3, thing4, thing4]); \\test2 sh2.appendRow([ID, thing1]); sh2.appendRow([ID, thing2]); sh2.appendRow([ID, thing3]); sh2.appendRow([ID, thing4]); sh2.appendRow([ID, thing5]); }Si el problema es que las nuevas filas se crean a pesar de que no existe una identificación para estos registros, primero asegúrese de que exista la identificación antes de escribir en la hoja. Así que en tu código, harías:
if( thing1 ) sh2.appendRow([ID, thing1]) if( thing2 ) sh2.appendRow([ID, thing2]) // … and so on