Minghan Wang
Minghan Wang

Reputation: 17

Google app script time trigger error

function try_A(){
   var range = SpreadsheetApp.getActiveSheet().getRange("B1");
   var url = range.getValue();
   var url_array = url.split('=');
   var id = url_array[1];
   var folder = DriveApp.getFolderById(id); 
}

So the function try_A reads the url that links to the google drive folder, and parse it to get the folder id. However, if i set a time trigger to call it for example every 1 min, then it keeps notifying me an error like couldn't find info for the corresponding id, or i don't have permission.The error corresponds to this line: "var folder = DriveApp.getFolderById(id);". But if i run this function manually, there is no problem. Why is that? Thx in advance.

Upvotes: 1

Views: 370

Answers (1)

Alan Wells
Alan Wells

Reputation: 31320

It looks like you are always getting the cell "B1", so you can use:

function try_A() {
  var ss,sh,range,url;

  ss = SpreadsheetApp.getActiveSpreadsheet();
  sh = ss.getSheetByName('name here');
  range = sh.getRange("B1");

  Logger.log('ss: ' + ss)//View the Logs to see what is printed
  Logger.log('sh: ' + sh)
  Logger.log('range: ' + range)

  url = range.getValue();
  Logger.log('url: ' + url)

  var url_array = url.split('=');
  var id = url_array[1];
  var folder = DriveApp.getFolderById(id); 
}

Upvotes: 1

Related Questions