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

289
Visualizações
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 Respostas
Responde à pergunta

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 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