-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathCreateBulkClassroom.js
62 lines (57 loc) · 1.81 KB
/
CreateBulkClassroom.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
This code is wriiten in Google Apps Script(JavaScript)
This code creates nulk Google Classroom using Google Apps Script
The Classes are created provided the following data is present in the Google Sheet
(1) Name of the Class
(2) Section of the Class
(3) Room
(4) Description of the Class
*/
OWNER_EMAIL = "aryanirani123@gmail.com"; //Don't forget to update this value with your email address :)
function onOpen(){
const menu = SpreadsheetApp.getUi().createMenu('Custom');
menu.addItem('Create Classroom','createClasses');
menu.addToUi();
}
function classroomData(properties){
const crs = Classroom.newCourse();
Object.keys(properties).forEach(key => {
Crs[key] = properties[key];
})
const createdCourse = Classroom.Courses.create(crs);
return createdCourse.enrollmentCode;
}
function createClasses(){
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getActiveSheet();
const START_ROW= 2;
const START_COLUMN = 1;
const LAST_COLUMN= 4;
const data = sheet.getRange(
START_ROW,
START_COLUMN,
sheet.getLastRow()-1,
LAST_COLUMN).getValues();
const enrollmentCodes = [];
const nameIndex = 0;
const sectionIndex = 1;
const roomIndex = 2
const descriptionIndex = 3;
const START_COLUMN = 5;
const LAST_COLUMN = 1;
data.forEach(row => {
const eCode = classroomData({
name: row[nameIndex],
section: row[sectionIndex],
room: row[roomIndex],
description: row[descriptionIndex],
ownerId: OWNER_EMAIL
});
enrollmentCodes.push([eCode]);
sheet.getRange(
START_ROW,
COLUMN_START,
enrollmentCodes.length,
COLUMN_LAST).setValues(enrollmentCodes);
});
}