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

278
Visualizações
If e.value = null or blank then leave blank
 var timestamp = e.values[0];
  var recipientName = e.values[1];
  var firstLineOfAddress  = e.values [2];
  var secondLineOfAddress = e.values[3];
  var thirdLineOfAddress = e.values[4];
  var postcode = e.values [5];
  var recipientEmail = e.values[6];
  var todaysDate = e.values[7];
  var invoicenNumber = e.values[8];
  var dueDate = e.values[9];
  var item1Description  = e.values [10];
  var item1Qty = e.values [11];
  var item1UnitPrice  = e.values [12];
  var item1Amount = e.values[13];


  var templateFile = DriveApp.getFileById("1VjJI3VUNSJDQuv8NsgSfSugIfi3c_ev4cGpbk5_LQ3I");
  var templateFolder = DriveApp.getFolderById("1MsmTVhosVz0S4Nquz2qMr-SZtYZYyV9S");

  var copy = templateFile.makeCopy(recipientName, templateFolder);
  var doc = DocumentApp.openById(copy.getId());

  var body = doc.getBody();

  body.replaceText("{{RECIPIENT NAME}}", recipientName);
  body.replaceText("{{FIRST LINE OF ADDRESS}}", firstLineOfAddress);
  body.replaceText("{{SECOND LINE OF ADDRESS}}", secondLineOfAddress);
  body.replaceText("{{THIRD  LINE OF ADDRESS}}", thirdLineOfAddress);
  body.replaceText("{{Postcode}}",postcode);
  body.replaceText("{{EMAIL}}",recipientEmail);
  body.replaceText("{{DATE}}",todaysDate);
  body.replaceText("{{REF}}", invoicenNumber);
  body.replaceText("{{DUEDATE}}", dueDate);
  body.replaceText("{{desc1}}", item1Description);
  body.replaceText("{{qty1}}", item1Qty);
  body.replaceText("{{unitprice1}}", item1UnitPrice);
  body.replaceText("{{amount1}}", item1Amount)



  doc.saveAndClose();

}

Im still learning googleappscript/java so apologies for sounding dumb. Im using a form to produce a invoice however I would like the variable of e.values[10] to be able to be cleared from the doc it produces if left blank.

So if e.value is blank then it body.replace text should replace it with nothing. If e.value is filled in then body.replace text should fill in with the appropriate response.

Any ideas how I can do this?

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

0

Each submission in form always contains timestamp. So when a user leave a question in blank, the value of it in e.values is just empty. It will produce something like this: [3/4/2022 5:50:53, , , , , , , , , , , , ].

Empty values works in body.replaceText() and not produce error. Hence you don't need to change anything in your code.

In case you have null value in your e.values, which can be done by editing the content of e.values, just append a ||'' next to the replacement string.

Your code should look like this:

body.replaceText("{{RECIPIENT NAME}}", recipientName||'');
body.replaceText("{{FIRST LINE OF ADDRESS}}", firstLineOfAddress||'');
body.replaceText("{{SECOND LINE OF ADDRESS}}", secondLineOfAddress||'');
body.replaceText("{{THIRD  LINE OF ADDRESS}}", thirdLineOfAddress||'');
body.replaceText("{{Postcode}}",postcode||'');
body.replaceText("{{EMAIL}}",recipientEmail||'');
body.replaceText("{{DATE}}",todaysDate||'');
body.replaceText("{{REF}}", invoicenNumber||'');
body.replaceText("{{DUEDATE}}", dueDate||'');
body.replaceText("{{desc1}}", item1Description||'');
body.replaceText("{{qty1}}", item1Qty||'');
body.replaceText("{{unitprice1}}", item1UnitPrice||'');
body.replaceText("{{amount1}}", item1Amount||'') 
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