• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
    • Questions
    • Teachers
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

191
Views
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;
}

almost 3 years ago · Juan Pablo Isaza
1 answers
Answer question

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.

almost 3 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error