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

291
Vistas
WebApp: How do I call a new function on the server after the previous has finishes (Callback)?

I have been trying for hours now to code a simple AppsScript. When a function on a WebApp server has successfully finished, I want to send the results back to my client (index.html) and call the next function on the server. For some reason, I cannot call a new server function from within my callback function. The first callback is executed - Alert "Callback1" is shown - but the new server function createSheetsLogfile(selectedLabel) is not called after. What am I doing wrong? Is it not possible to call a function on the server from within a callback function?

Thank you very much for your help! Best wishes, Ben

index.html

<button onclick="archiveSBEmails()">Start archiving</button>

<script>
var selectedLabel = "";

function archiveSBEmails(){
    selectedLabel = "Testlabel_1";
    google.script.run.withSuccessHandler(callbackFolderCreated).createFolder(selectedLabel);
 } 
       
function callbackFolderCreated(){
     alert("Callback1");
    google.script.run.withSuccessHandler(callbackLogfileCreated).createSheetsLogfile(selectedLabel);      
}


function callbackLogfileCreated(logfileURL){
    alert("Callback2");
    google.script.run.withSuccessHandler(callbackBackupCompleted).BackupGmailToDrive(selectedLabel);     
}     


function callbackBackupCompleted(){
/...
 }


</script>

code.gs

function doGet() {
  return HtmlService.createHtmlOutputFromFile('index')
            .setSandboxMode(HtmlService.SandboxMode.IFRAME);
}

function createFolder(selectedLabel){  
  //function is called from index.html
  // some code ...
    return true;
}

function createSheetsLogfile(selectedLabel){
  //function is called from index.html
  //some code...
  return logfileURL;
}

function BackupGmailToDrive(selectedLabel){
  //function is called from index.html
  //some code..
  return true;
}

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I declared and initialized a global variable outside of any function earlier in the code which was then reset to "" again everytime a function in code.gs was called. To solve the problem, I deleted the global variable and introduced another parameter to be handed over to the functions where needed.

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