AppScript for Google Sheets Refuses to Run


This Content is from Stack Overflow. Question asked by Skello

I’m not sure why it won’t, since I’ve already addressed the oAuthScope issues for it, but for some reason this code refuses to run.

Here’s my appsscript.json file:

  "timeZone": "America/New_York",
  "dependencies": {
  "exceptionLogging": "STACKDRIVER",
  "oauthScopes": [
  "runtimeVersion": "V8",
  "sheets": {
    "macros": [{
      "menuName": "writeStudents",
      "functionName": "writeStudents"

Here’s the code that doesn’t run:

function writeStudents() {
  var activeFolder = DA.getFolderById(getActiveFolder_());
  var studentItr = activeFolder.getFiles();
  var rows = SS.getRange(ActiveStudents_).getValues();
  rows = => x = ['', '']);
  var idx = 0;
  while (studentItr.hasNext()) {
    var student =;

    rows[idx++] = [student.getName(), student.getId()];

function getActiveFolder_() {
  var year = new Date().getFullYear();
  var folder = SS.getRange(ActiveStudentsFolders_).getValues()
    .filter(row => row[0] == year);
  return folder[0][1];

I have this particular code in a trigger that’s supposed to run upon opening the file, and the only error I get is that I don’t have the right permissions, and gives me the link to add to my appscript.json file:

Exception: You do not have permission to call DriveApp.getFolderById. Required permissions: ( ||

at writeStudents_(Overview:2:25)
at writeStudents(Public:26:3)
at onOpen(Events:3:3)

You’ll definitely find those auths inside the json file.

Now to explain a couple of things:

The DA and SS are DriveApp and SpreadsheetApp.getActiveSpreadsheet() respectively, that I’ve turned into alias variables so that I can use them with shorter names.

ActiveStudents_ and ActiveStudents_ are also variables for the named ranges I’m using inside the script. These are also correct, since, at one point before this one, I managed to get this code to work.

As for the error call stack: I made a file for testing all of the functions, spread across several script files, in one place, by making public wrapper functions of all the functions I wanted to eventually be public. That part does work. However, when I found that this function did not, I used the original function, publicized it, and tested it from its original file. All it does is spin forever, and doesn’t even make it to the first line in the function, even when adding a break point.

To make matters worse, I can’t even get a basic console log to work. I just tried this:

function test() {
  console.log('Are you working at all?!');

It just hangs there, not doing anything.

What’s going on here?


Check the Answers

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?