Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

86
Visualizações
Transposed content issue

trust you're good. I'm working on a project where I sent data from an apk to a google sheet. The fact is that I sent the whole data to a sheet and I also send a kind of transposed data to other sheets, all with custom IDs.

Example here:

In Test_Sheet: ID Region Place Staff thing1 thing2 thing3 thing4 thing5

In test2 sheet:

ID thing1

ID thing2

ID thing3

ID thing4

ID thing5

All works fine but my issue is that when I have fewer items only, the ID will still be in the test2 sheet like all items are present.

ID thing1

ID thing2

ID thing3

ID

ID

Here is the code:

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

}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

If the problem is that the new rows are created even though an ID does not exists for these records, then first make sure that the ID does exist before writing to the sheet. So in your code, you would do:

 if( thing1 ) sh2.appendRow([ID, thing1])
 if( thing2 ) sh2.appendRow([ID, thing2]) 
 // … and so on
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda