{"id":"code-work-fin-apps-script-lock-month","audience":"finance","category":"coding","track":"coding","technique":"constraints","title":"Lock a closed month's tab with a short Apps Script","free":false,"task":"Write a Google Apps Script function named lockMonth that protects the whole tab named 2026-10 after the October close. The protection description must be Closed - do not edit, and the only editor left must be the controller, kofi.mensah@northgate.example: remove everyone else and turn off domain editing. You'll run it by hand, so no menus, triggers, logging or try/catch. One code block, at most 12 lines, then under 25 words outside the code.","materialLabel":"Workbook details (attached to your prompt automatically)","material":"MONTH-END WORKBOOK - Northgate Supply (Google Sheets)\n\nTabs: 2026-08, 2026-09, 2026-10, 2026-11 (draft), Lookups, Dashboard\n\nPeople with edit access today:\n- kofi.mensah@northgate.example (controller, owner)\n- ama.boateng@northgate.example (bookkeeper)\n- raj.mehta@northgate.example (FP&A)\n- Anyone at northgate.example can edit (link sharing)\n\nWhat went wrong in September:\n- Someone pasted over three accrual lines in the 2026-09 tab two weeks after close.\n- We only noticed during the audit prep call.\n- Version history fixed it, but it took an afternoon.\n\nNotes:\n- The Dashboard tab reads from every month tab, so the tabs can't be hidden.\n- Ama needs to keep editing 2026-11 while November is open.\n- The workbook is about 4 MB.","rules":[{"type":"codeBlocks","count":1},{"type":"maxCodeLines","max":12},{"type":"maxProseWords","max":25}],"mistakes":[{"title":"Not naming the tab","why":"The AI protects the active sheet or a range, so the wrong thing gets locked.","fix":"Add: \"Protect the whole tab named 2026-10.\"","checks":["r0"]},{"title":"Leaving the label open","why":"The AI writes its own description, so people don't see why it's locked.","fix":"Add: \"Description: Closed - do not edit.\"","checks":["r1"]},{"title":"Not saying who keeps access","why":"Protection keeps current editors by default, so Ama and the whole domain can still edit.","fix":"Add: \"Remove all editors, add only Kofi, turn off domain editing.\"","checks":["r2"]},{"title":"Getting a menu of options","why":"The AI likes to offer two or three versions of the script, so you're left to pick and test them yourself.","fix":"Add: \"Give one script only, in one code block, no alternatives.\"","checks":["codeBlocks","maxCodeLines"]},{"title":"Getting a tutorial","why":"By default the AI explains every part of the code at length, which you then have to scroll past.","fix":"Add: \"After the code, one line under 12 words. Nothing else.\"","checks":["maxProseWords"]}],"promptHints":[{"label":"Names the function and tab","patterns":["lockmonth","2026-10"]},{"label":"Sets the description","patterns":["closed - do not edit","description"]},{"label":"Says who keeps access","patterns":["kofi","only (the )?controller","remove (all|every)","domain"]},{"label":"Rules out extras","patterns":["no (menu|trigger|logging|try)","try/catch"]},{"label":"Caps the code length","patterns":["\\d+\\s*lines","at most","under \\d+","short"]}],"hint":"Protecting a sheet doesn't remove anyone by itself. Tell the AI exactly which tab, the label, and who should be left with access.","rubricLabels":["Is a function named lockMonth that gets the tab with getSheetByName(\"2026-10\") and protects the whole sheet (sheet.protect()), not a range","Sets the description to exactly Closed - do not edit","Removes the current editors (removeEditors(getEditors())), adds kofi.mensah@northgate.example, turns off domain editing (setDomainEdit(false)), and has no menu, trigger, Logger.log or try/catch"]}