Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

284
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda