Return data the page can read
Turns dates into text and drops values the page can't receive, so a result never arrives as null.
File Code.gs
/** A copy of `value` the page can receive: every Date becomes ISO text (JSON does that), undefined fields are dropped. */
function plain_(value) {
return value === undefined ? null : JSON.parse(JSON.stringify(value));
}
function getDashboard() {
const rows = SpreadsheetApp.openById(SHEET_ID).getSheetByName('Orders').getDataRange().getValues();
return plain_({ updated: new Date(), count: rows.length - 1, last: rows[rows.length - 1] });
}
Good to know
- Symptom this fixes: the function returns data in the editor, but the page gets null with no error.
- Apps Script cannot send Date, functions or class instances to the page; one of them anywhere makes the whole result null.
Let the AI put it in your appGAS AI Builder knows every recipe here. Describe your app and it uses this code where it fits, in a Google Apps Script project in your own Drive.
Use it in a projectMore in Web app
Who is using the app, and their roleReads the visitor's email and looks up their role in a Users tab; server functions check it before doing anything.doGet with pages split into filesindex.html pulls in css/app.html and js/app.html with include(); works on phones and inside an iframe.Call the server from the page with async/awaitA small helper turns google.script.run into a promise, with errors shown instead of lost.Upload a file from the page to DriveThe page reads the chosen file as base64 and sends it; the server saves it in a folder and returns its link.