← Back to session 1

Reference example

Sleep diary: the parts and the tests

A private log with two columns, Data and Hores. Use it to compare the code AI suggests and practise the connection. It is not prepared for collecting health data or sharing with others.

Download Codi.gs · Download Index.html

Set it up in your practice account

  1. Create a spreadsheet with a Registres tab. In row 1, enter Data in A1 and Hores in B1. Leave the rest empty.
  2. Open Extensions → Apps Script. Copy Codi.gs into the code file and Index.html into an HTML file named Index. If the browser opens the frontend instead of downloading it, use the save-file option.
  3. In Codi.gs, replace ENGANXA_AQUI_ID_DEL_FULL with the spreadsheet document ID, inside quotes. It is the part of the address after /spreadsheets/d/. Do not enter the full URL or the Script ID.
  4. Save and run comprovaConnexio from the editor. Review the account and Sheets permissions before authorising. If you do not understand the permissions or the project, stop.
  5. Deploy a Web app, running as your account with Only myself or equivalent restricted access. Open /exec with that account. Do not make access public to bypass a configuration problem.

What should happen

Deploy a change without losing the link

Save a copy of the code. Change some text in Index.html, save and update the existing deployment through Manage deployments → Edit → New version. Check the same /exec and repeat the tests. To recover from an incorrect change, select the previous version in that deployment.

Example validation: the repository includes local tests using simulated services for configuration, validation, writing, reading and error messages. They do not equal a real Google Apps Script run: authorisation, deployment and access must be tested in the account you use.

Official references

Bound scripts and active-context limits · Web apps and execution identity · Service authorisation · Browser-server communication