Home > other >  Order of running two consecutive appscripts
Order of running two consecutive appscripts

Time:01-14

Is there any reason why two scripts in the same function is working in one order and not in another order? I have two functions, when I run FolderLists first then FolderMaker runs after but if I run FolderMaker first then Folder list is not running.

function Button(e) {
  var sheet = e.source.getActiveSheet();
  if (sheet.getName() === 'answers') {

      FolderMaker();
      SpreadsheetApp.flush();
      Utilities.sleep(3000)
      FolderList();

}
}

function FolderMaker(){
      createFoldersTasks_();
      createFolderByTask_();
      createFolders_();
      createFolderInFolder_();
      isFolderInFolder_();
}

function FolderList(){
      listFolers();
}

CodePudding user response:

I am not sure what you mean to say, is it like when you are calling like this:`

function Button(e) {
      FolderMaker();
      FolderList();
}

It is working correctly, but when you try this:

function Button(e) {
      FolderList();
      FolderMaker();
}

It is not working,I will suggest you that you can try debugging using msgbox or adding breakpoints, try this code it will show a message box in the google sheet if you edit the sheet named "answers"

function onEdit(e) {
  var sheet = e.source.getActiveSheet();
  if (sheet.getName() === 'answers') {
      FolderMaker();
      SpreadsheetApp.flush();
      Utilities.sleep(300)
      FolderList();

}
}

function FolderMaker(){
      Browser.msgBox('called FolderMaker');
}

function FolderList(){
      Browser.msgBox('called FolderList');
}

`

CodePudding user response:

There is no reason for it, the order should not matter

  • If the second function does not run, most likely some of the functions called by the first function resulted in an error that stopped the further script execution. Please check your executions.
  • Alternatively, the script stopped executing, because it surpassed the enter image description here


  •  Tags:  
  • Related