Home > Net >  Create assignment in google classroom with link youtube using google apps script
Create assignment in google classroom with link youtube using google apps script

Time:01-18

I want to add an assignment in Google Classroom by including the YouTube link, but when I run there is an error notification, namely "Message details TypeError: Cannot read properties of null (reading 'getRange')"

function assignmentWithLink(){
  const ss = SpreadsheetApp.getActiveSpreadsheet();
  const sheet = ss.getSheetByName('ASSIGNMENT (Youtube | Link)');
  const courseId = sheet.getRange('B1').getValue();
  const topicId = sheet.getRange('B2').getValue().toString();
  var assignment = {
    topicId : topicId,
    title: sheet.getRange('B3').getValue().toString(),
    description: sheet.getRange('B4').getValue().toString(),
    materials:[
      {link: {url: sheet.getRange('B5').getValue().toString() }},
    ],
    maxPoints: sheet.getRange('B6').getValue().toString(),
    state: "PUBLISHED",
    workType: "ASSIGNMENT"
  };
  const newCourseAssignment = Classroom.Courses.CourseWork.create(assignment, courseId);
  const assId = newCourseAssignment.id;
  sheet.getRange('D1').setValue(assId);
  copyToAll()
}

what should i do in the code range to make it readable? Hopefully friends can help me solve my problem. All your answers are very valuable to me.

CodePudding user response:

It's very likely that the sheet name in

const sheet = ss.getSheetByName('ASSIGNMENT (Youtube | Link)');

doesn't match a sheet name in the active spreasheet. The name should match exaclty (same case, same spaces).

  • Related