2
votes

Seems like onEdit(e) won't trigger creating a new folder in google drive - only works when running it explicitly. Any ideas? Thanks

function onEdit(e) {
  var requestRow = e.range.getRow();
  var folderName = SpreadsheetApp.getActiveSheet().getRange(requestRow,6).getValue();
  var newFolder = DriveApp.getFolderById('1LOfkVGrV-juzUiwbU8owHj74T9wMAz').createFolder(folderName);
}
1
Simple onEdit(e) triggers do not have authorisation to call DriveApp, you need to set this up as an installable trigger instead.ross
Like Ross mentioned, you should use installable triggers instead, here is instructions for itAMolina

1 Answers

0
votes

Try this:

function func1(e) {
  DriveApp.getFolderById('1LOfkVGrV-juzUiwbU8owHj74T9wMAz').createFolder(SpreadsheetApp.getActiveSheet().getRange(e.range.rowStart,6).getValue());
}

function isTrigger(funcName){
  var r=false;
  if(funcName){
    var allTriggers=ScriptApp.getProjectTriggers();
    for(var i=0;i<allTriggers.length;i++){
      if(funcName==allTriggers[i].getHandlerFunction()){
        r=true;
        break;
      }
    }
  }
  return r;
}

Run this once to create the trigger.

function createOnEditTrigger() {
  if(!isTrigger('func1')){
    ScriptApp.newTrigger('func1').forSpreadsheet(SpreadsheetApp.getActive().getId()).onEdit().create();
  }
}