Google Apps Script recipes
Tested code for the jobs most Apps Script projects need. Copy it into your project, or let GAS AI Builder add it for you.
Sheets as a database
Add a row safely when many people save at onceLockService keeps two saves from writing the same row; the row gets an Id and the time it was made.Write many rows at onceBuild a 2-D array and write it with one setValues call instead of one call per cell.A dropdown list from another sheetKeeps the choices in their own tab (Lists) and puts a dropdown on a column that follows that list.Make a sheet with its header oncesetup() creates the tabs the app needs with a bold, frozen header, and adds missing columns to tabs that exist.Read a sheet as a list of objectsOne getValues() call, the first row as field names, dates turned into text so google.script.run can return them.Update or delete a row by its IdFinds the row by the Id column with TextFinder and writes the changed fields in one setValues call.
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.Return data the page can readTurns dates into text and drops values the page can't receive, so a result never arrives as null.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.
Dates, text and numbers
Dates in Indonesian"Selasa, 3 November 2026" and "03/11/2026 14:05" in the script's time zone.Turn text from the page into a dateAn <input type="date"> sends "2026-11-03"; new Date() on it gives midnight UTC, a day early or late in some zones. This reads it in the script's time zone.Running numbers like INV-2026-0001A counter in Script Properties, raised under a lock so two people never get the same number; starts again each year.
Email, Docs, Forms and PDF
Fill a Doc template and save it as PDFCopies a Google Doc with {{placeholders}}, fills them in, saves a PDF in a folder and removes the copy.Make a real Google Form with codeCreates a Google Form once, keeps its ID, sends its responses to the project's Sheet and returns its links.Send an HTML email from a templateThe email body is an HTML file with <?= name ?> fields; checks the daily email quota first.
Drive files
Get or make a folder by nameFinds a folder by name inside a parent (or makes it), so files land in Reports/2026/11 without duplicates.Share a file with someoneGives one person view or edit access to a file without the notification email Google sends by default.Read the text of a PDF or photo (OCR)Turns a PDF or picture into text with Google's OCR through the Advanced Drive service (v2 or v3), then removes the temporary Doc.
Triggers and long jobs
Finish a long job in parts (6-minute limit)Works through rows until about 5 minutes have passed, remembers where it stopped, and schedules itself to go on.Stamp the time when a row is editedAn onEdit function writes the time into an "Updated" column whenever someone edits that row.Run a function every day at a set hourInstalls one time trigger for a function, removing older ones for it first so it never runs twice.
APIs, cache and settings
Make slow reads fast with a cacheKeeps the result of a slow read for a few minutes, so a page that opens often doesn't read the whole sheet each time.Call an API with retriesCalls an address, reads JSON, and tries again after a short wait when the service is busy (429 or 5xx).Keep settings and secrets out of the codeScript Properties hold API keys and settings; a setup function asks for them once.
Sheet formulas
=EMAIL_VALID(text) – check email addressesTRUE when the text looks like an email address; catches spaces, missing @ and common typos like gmial.com.
=EMAIL_VALID()=HARI_KERJA_LIBUR(start; end; holidays) – working days with a holiday tabCounts working days between two dates, skipping the holidays listed in a range; =HARI_KERJA_LIBUR(B2; C2; Libur!A:A; 6) counts Saturdays as work days.=HARI_KERJA_LIBUR()=JSON_GET(json; path) – read a value from JSON in a cell=JSON_GET(A2; "customer.name") or "items.0.price" pulls one value out of JSON stored in a cell.=JSON_GET()=NOMOR_HP(phone) – one format for phone numbers"0812-3456-7890" and "+62 812 3456 7890" both become 6281234567890, the form WhatsApp links need.=NOMOR_HP()=RUPIAH(amount) – "Rp 1.250.000" as textFormats a number as rupiah text with dots between thousands, for labels, emails and documents made from the Sheet.=RUPIAH()=SLUG(text) – short ids from names"Kopi Susu Gula Aren (Large)" becomes "kopi-susu-gula-aren-large", for codes, file names and links.=SLUG()=TANGGAL_INDO(date) – "Selasa, 3 November 2026"Writes a date with Indonesian day and month names; =TANGGAL_INDO(A2; FALSE) leaves out the day name.=TANGGAL_INDO()=TERBILANG(amount) – numbers in Indonesian words=TERBILANG(1250000) gives "satu juta dua ratus lima puluh ribu rupiah". Works on a whole column too.=TERBILANG()=UMUR(birth date) – age or length of service=UMUR(B2) gives "34 tahun 2 bulan"; =UMUR(B2; C2) counts up to another date (e.g. masa kerja until leaving).=UMUR()Let the AI put it in your appGAS AI Builder knows every recipe here. Describe your app and it uses these where it fits, in a Google Apps Script project in your own Drive.
Start building