Function within another function in javascript


I have a web app to approve the responses of a form through an email.

In addition to that, I would like you to send me some emails that would be conditional on some of the responses on the form.

In order to simplify the code and give it a bit of order, I thought about:

  1. Do it in the same project, but in a different script file.
  2. In my main function (the one that fires via email) call the function that is in the other script file.

How can I do that?


DLIBRO = "1JN41GTgAl8Vl8gqGbBcyfaMs......." 

IDHOJA = "Respuestas"

function doGet(e) {

  var numeroAutorizacion = e.parameter['IdAprob']

  var hoja = SpreadsheetApp.openById(IDLIBRO).getSheetByName(IDHOJA)

  var aprobacion = hoja.getRange('I' + numeroAutorizacion).setValue("Si")

  var hoy = hoja.getRange('J' + numeroAutorizacion).setValue(new Date())


Where mail is the other function.


In the first version of the question it is mentioned that the shared code did not work. This is because the statements have not been separated with a semicolon.

Regarding whether it is possible to include several files in the same project and place different functions in this if possible. Calling a function that is in another file in the same project is very easy. Example:

function principal() {
   //Llama la función llamada secundaria().
} code

function secundaria() {
   //Agrega al registro un mensaje de júbilo.
   Logger.log('Me llamaron. ¡Viva!'); 

Considering the type of error, you might want to review a JavaScript course or the JavaScript guide published by the Mozilla Developers Network (MDN), since Google Apps Script is based on that language.

As for resources on Google Apps Script in Spanish, the following playlist from the Google Developers channel could be useful for you: Introduction to Google Apps Script

Scroll to Top