This guide will walk you through turning a standard Google Sheet into a connected database for your mobile evaluation app.
Phase 1: Prepare Your Google Sheet
The app requires a specific sheet structure to read your class roster and save marks accurately.
- Create a new Google Sheet for your module or cohort.
- Double-click the tab name at the very bottom left of the screen (it usually defaults to “Sheet1”) and rename it to exactly Evaluations (Case-sensitive, no spaces).
- Create your column headers in the first row. You must include Student ID, Good Name, Average, and Attempts.
- Add your grading columns (e.g., Session 01, Session 02). Ensure there are no hidden spaces at the end of these names.
- Populate the rows below the headers with your student data.
Phase 2: Add the Apps Script
This script acts as the bridge between your Google Sheet and the mobile app.
- In your Google Sheet, click Extensions in the top menu and select Apps Script.
- Delete any code currently in the editor.
- Copy and paste the complete script below into the editor:
const TAB_NAME = "Evaluations";
function getTargetSheet() {
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheetByName(TAB_NAME);
if (!sheet) {
throw new Error("Target sheet not found. Looking for tab named: " + TAB_NAME);
}
return sheet;
}
function doGet(e) {
try {
const sheet = getTargetSheet();
const data = sheet.getDataRange().getDisplayValues();
if (!data || data.length === 0) throw new Error("Sheet is completely empty.");
const headers = data[0].map(h => h.toString().trim());
let students = [];
for (let i = 1; i < data.length; i++) {
let rowObj = {};
for (let j = 0; j < headers.length; j++) {
rowObj[headers[j]] = data[i][j];
}
rowObj["_rowIndex"] = i + 1;
students.push(rowObj);
}
return ContentService.createTextOutput(JSON.stringify({ status: "success", headers: headers, students: students }))
.setMimeType(ContentService.MimeType.JSON);
} catch (error) {
return ContentService.createTextOutput(JSON.stringify({ status: "error", message: "Read Error: " + error.toString() }))
.setMimeType(ContentService.MimeType.JSON);
}
}
function doPost(e) {
try {
const sheet = getTargetSheet();
if (!e || !e.postData || !e.postData.contents) {
return ContentService.createTextOutput(JSON.stringify({ status: "error", message: "No data payload received." }))
.setMimeType(ContentService.MimeType.JSON);
}
const payload = JSON.parse(e.postData.contents);
const headers = sheet.getDataRange().getDisplayValues()[0].map(h => h.toString().trim());
const targetSession = payload.sessionName ? payload.sessionName.toString().trim() : "";
const targetColumn = headers.indexOf(targetSession) + 1;
if (targetColumn > 0) {
sheet.getRange(payload.rowIndex, targetColumn).setValue(payload.mark);
SpreadsheetApp.flush();
return ContentService.createTextOutput(JSON.stringify({ status: "success", message: "Mark saved successfully!" }))
.setMimeType(ContentService.MimeType.JSON);
} else {
return ContentService.createTextOutput(JSON.stringify({ status: "error", message: "Column '" + targetSession + "' not found." }))
.setMimeType(ContentService.MimeType.JSON);
}
} catch (error) {
return ContentService.createTextOutput(JSON.stringify({ status: "error", message: "Write Error: " + error.toString() }))
.setMimeType(ContentService.MimeType.JSON);
}
}
- Click the Save icon (the floppy disk) at the top of the editor.
Phase 3: Deploy as a Web App
You must deploy the script so the mobile app can access it securely.
- Click the Deploy button at the top right of the Apps Script editor.
- Select New deployment.
- Click the gear icon next to “Select type” and choose Web app.
- Add a description (e.g., “Student Evaluation Backend”).
- Under Execute as, select Me.
- Under Who has access, select Anyone.
- Click Deploy.
- Google will prompt you to authorize access. Click Authorize access, choose your Google account, click Advanced, and click Go to [Project Name] (unsafe) to allow the script to edit your spreadsheet.
- Once authorized, copy the Web app URL provided.
Important Note for Future Updates: If you ever change the script code, you must go to Deploy > Manage deployments, click the Pencil icon to edit, and select New version before clicking Deploy. Simply saving the script will not update the live app.
Phase 4: Connect the Mobile App
Your backend is now ready to receive grades.
- Open the Evaluation Mobile App on your device.
- Tap the + button (Add New Sheet).
- Give your sheet a recognizable name (e.g., “Term 1 Cohort”).
- Paste the Web app URL you copied in Phase 3.
- Tap Save.
- Tap your newly added sheet from the list. The app will securely fetch your roster, and you are ready to begin grading.
