Search code examples
google-apps-scriptgoogle-classroom

How to use DRAFT enum in Google Classroom CourseWork.list call


I've have assigned hundreds of Classroom assignments to 40 different courses using CourseWork.create from a Google Script associated with a Google Sheet. Within CourseWork.create I use state = "DRAFT" and scheduledTime to a time in the future to publish at a later date. All working great.

Sometimes I lose track of what I have assigned. When I use Classroom.Courses.CourseWork.list(course id) I get a list of all published but not the draft assignments to be published later. The documentation suggests that as owner of the course I should be able to list all work.

So I tried using the enum value DRAFT. I'm not sure of the syntax to use. I've tried

  Classroom.Courses.CourseWork.list(id, courseWorkStates="DRAFT");
  Classroom.Courses.CourseWork.list(id, courseWorkStates=DRAFT);
  Classroom.Courses.CourseWork.list(id, courseWorkStates=Classroom.DRAFT);

  Classroom.Courses.CourseWork.list(course id, "DRAFT");

  Classroom.Courses.CourseWork.list(id, enum("DRAFT"));

  Classroom.Courses.CourseWork.list(id, Classroom.DRAFT);  // this gives a Server error

  Classroom.Courses.CourseWork.list(id, Classroom.Atrribute.DRAFT);

Solution

  • You need to pass in an options Object (with the courseWorkStates property set to "DRAFT") as your second argument to the Classroom.Courses.CourseWork.list() method.

    var options = {};
    
    options.courseWorkStates = "DRAFT";
    
    Classroom.Courses.CourseWork.list(id, options);