-
Notifications
You must be signed in to change notification settings - Fork 0
/
ImportIntoTENTATIVE.js
125 lines (96 loc) Β· 5.62 KB
/
ImportIntoTENTATIVE.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/**
importDataToDestination completes two processes:
1. importDataToDestination calls the registrationsData function in the "sourceScript" file of this project and an object is
returned that includes all of the students from Registrations SY 23.24.
2. importDataToDestination references TENTATIVE (2023-2024 NAHS
Student Transition Notes) and cross references the student IDs from both lists. If a student ID does not exist, it will:
1. append the students to TENTATIVE;
2. it then calls function importEmails which references the ContactInfo sheet and adds the student emails, guardian name and guardian emails into column BY, BZ, and CA;
3. it calls function copySchedulesToTentative to get all of the course titles, teacher names, and case manager names from the Schedules sheet;
4. it calls function matchAndCopyValues to get the teacher comments from the Form Responses 1 sheet into their designated spots;
5. it sorts the list in alphabetical order by last name then first; then
6. it adds checkboxes if they're missing in column BX.
Point of contact: Alvaro Gomez, Special Campuses Academic Technology Coach, 210-363-1577
Last update: 11/21/23
*/
function importDataToDestination() {
SpreadsheetApp.getActiveSpreadsheet().toast('The script is currently running. ππ»ββοΈ It is updating the roster, contact info., and teacher input. Please stand by...', 'Updating Sheet', -1);
let data = registrationsData();
let destinationSpreadsheetId = '1MTg2DdLGRKtdb2KuVwU-vmn-L_4dIUzW7uKp_AYSVI4';
let destinationSpreadsheet = SpreadsheetApp.openById(destinationSpreadsheetId);
let destinationSheet = destinationSpreadsheet.getSheetByName('TENTATIVE');
// Get existing Student IDs from the destination sheet
let existingStudentIds = destinationSheet.getRange(2, 4, destinationSheet.getLastRow()).getValues(); // 'Student ID' is in column D (index 4)
for (let i = 0; i < data.length; i++) {
let rowData = data[i];
let studentId = rowData['Student ID'];
// Check if the Student ID exists in the destination sheet
if (existingStudentIds.flat().indexOf(studentId) === -1) {
// Extract specific values from rowData
let valuesToImport = [
new Date(),
rowData['Student Last Name'],
rowData['Student First Name'],
rowData['Student ID'],
rowData['Grade'],
rowData['Home Campus'],
rowData['Start Date'],
rowData['Projected Exit'],
rowData['Eligibility'],
rowData['Behavior Contract']
];
// Specify the target columns using targetColumnIndices
let targetRow = [
valuesToImport[0], valuesToImport[1], valuesToImport[2], valuesToImport[3], valuesToImport[4],
'', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', '',
valuesToImport[5], valuesToImport[6], valuesToImport[7], '', '', '',
valuesToImport[8], '', valuesToImport[9]
];
destinationSheet.appendRow(targetRow);
}
}
SpreadsheetApp.getActiveSpreadsheet().toast('π§ Importing the contact info now. Please stand by...', 'Updating Contact Info.', -1);
importEmails();
SpreadsheetApp.getActiveSpreadsheet().toast('β° Copying the schedules over. Please stand by...', 'Updating Schedules', -1);
copySchedulesToTentative();
SpreadsheetApp.getActiveSpreadsheet().toast('π©π»βπ« Adding the teacher comments. This is the step that takes a long time. Please stand by...', 'Updating Teacher Comments', -1);
matchAndCopyValues();
SpreadsheetApp.getActiveSpreadsheet().toast('π
Almost done, sorting the sheet and adding the finishing touches. Please stand by...', 'Sorting Sheet', -1);
// Sort the rows based on columns B and C
var rangeToSort = destinationSheet.getRange('A2:CE' + destinationSheet.getLastRow());
// Get values and trim leading/trailing spaces
var valuesToSort = rangeToSort.getValues().map(row => row.map(cell => cell.toString().trim()));
// Set the values back to the range
rangeToSort.setValues(valuesToSort);
// Sort the range
rangeToSort.sort([{column: 2, ascending: true}, {column: 3, ascending: true}]);
// Get the range of data after sorting
let sortedDataRange = destinationSheet.getRange('A2:CE' + destinationSheet.getLastRow());
// Insert checkboxes in column BX (index 75 after sorting) if missing
let checkBoxColumn = sortedDataRange.offset(0, 77 - 2, sortedDataRange.getNumRows(), 1);
// Get existing values in the checkbox column
let existingCheckboxes = checkBoxColumn.getValues();
// Loop through the existing checkboxes and insert if missing
for (let i = 0; i < existingCheckboxes.length; i++) {
if (existingCheckboxes[i][0] !== true) {
checkBoxColumn.getCell(i + 1, 1).insertCheckboxes();
}
}
SpreadsheetApp.getActiveSpreadsheet().toast('Script finished updating! ππΌ You are free to work on it now.', 'Finished', 5);
insertNoteWithTimestamp();
}
function insertNoteWithTimestamp() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("TENTATIVE");
// Get the current timestamp
var currentTime = new Date();
// Get the spreadsheet's time zone
var timeZone = SpreadsheetApp.getActiveSpreadsheet().getSpreadsheetTimeZone();
// Format the timestamp using the spreadsheet's time zone
var formattedTime = Utilities.formatDate(currentTime, timeZone, "yyyy-MM-dd HH:mm:ss a");
// Construct the note
var note = "The TENTATIVE Sheet was updated on: " + formattedTime;
// Set the note to cell A1, overwriting any existing note
sheet.getRange('A1').setNote(note);
}