{"id":"code-work-office-apps-script-copy-approved","audience":"office","category":"coding","track":"coding","technique":"constraints","title":"Copy approved requests to another tab with Apps Script","free":false,"task":"Write a Google Apps Script function named copyApproved that copies every row from the Requests tab whose Status (column D) is Approved onto the bottom of the Approved tab. Copy only columns A to D, because the Approved tab has no Notes column, and skip the header row. Keep it to a function you run by hand: no menus, triggers, logging or try/catch. One code block, at most 15 lines, then under 25 words outside the code.","materialLabel":"Spreadsheet layout (attached to your prompt automatically)","material":"PURCHASE REQUESTS spreadsheet - shared by the office manager\n\nRequests tab (row 1 is headers)\nA Requested by | B Item | C Cost | D Status | E Notes\nAna Ortiz | Standing desk | $340 | Approved | needs delivery to 4th floor\nRaj Mehta | Monitor arm | $85 | Pending | waiting on Lou\nMei Wu | Label maker | $40 | Approved | \nLou Grant | Whiteboard | $120 | Denied | no wall space\nJae Kim | Headset | $65 | Approved | for the help desk\n\nApproved tab (row 1 is headers, then past approvals)\nA Requested by | B Item | C Cost | D Status\nPat O'Neil | Desk lamp | $30 | Approved\n\nNotes:\n- Finance reads the Approved tab every Thursday.\n- There's also a Budget tab with a chart on it.\n- The sheet is owned by the office manager's account.\n- Requests usually come in through a Google Form.","rules":[{"type":"codeBlocks","count":1},{"type":"maxCodeLines","max":15},{"type":"maxProseWords","max":25}],"mistakes":[{"title":"Not describing both tabs","why":"The AI copies whole rows, Notes included, into a tab that has only four columns.","fix":"Add: \"Copy only columns A to D; the Approved tab has no Notes column.\"","checks":["r1"]},{"title":"Leaving out the names","why":"The AI picks its own function name and uses the active sheet.","fix":"Add: \"Function copyApproved, get both tabs with getSheetByName, skip row 1.\"","checks":["r0"]},{"title":"Not ruling out extras","why":"The AI adds a custom menu, logging and error handling you didn't ask for.","fix":"Add: \"No menus, triggers, logging or try/catch.\"","checks":["r2","maxCodeLines"]},{"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 15 words. Nothing else.\"","checks":["maxProseWords"]}],"promptHints":[{"label":"Names the function and tabs","patterns":["copyapproved","requests","getsheetbyname"]},{"label":"Limits the columns","patterns":["a (to|-|through) d","four columns|4 columns","notes"]},{"label":"Rules out extras","patterns":["no (menu|trigger|logging|try)","logger","try/catch"]},{"label":"Asks for one answer only","patterns":["\\b(one|single|1)\\s+(script|function|code block|block|version)","only one","no (alternatives|options|other versions)"]},{"label":"Caps the code length","patterns":["\\d+\\s*lines","at most","under \\d+","short"]}],"hint":"Describe both tabs to the AI, including the column the Approved tab doesn't have, and say what you don't want added.","rubricLabels":["Is a function named copyApproved that gets the Requests and Approved tabs by name (getSheetByName) and skips the Requests header row","Copies only rows whose column D is Approved, and only columns A to D (not Notes in column E), adding them after the existing rows on the Approved tab (appendRow or getLastRow() + 1)","Has no onOpen menu, trigger, Logger.log or console.log, try/catch or UI alert"]}