Hands-On AI WorkshopHomeProjectsLearnResourcesPresenterHelpProgress

Project 13 of 30 · Pathway 3 — Gmail and Workspace Interfaces

Automated Task Management System

Overdue tasks get lost in a long list. Prioritize tasks by deadline.

Real-world benefit
Team deadlines, assignments and personal chores.
Technologies
Google Sheets, Dates, Time-driven triggers
Required knowledge
Comparing dates.
Time and level
About 25 minutes · Beginner
AI requirement
None: deterministic Apps Script
Expected baseline
Slides Overdue; Budget Open; Review Done.

Loading the interactive studio…

Introduction

markTasks preserves source rows and derives priority using status and ISO date comparison. The application's entry point is updateTasks(). Baseline limitation, as stated in the workshop: Workshop run uses fixed date; background access must be tested.

Key building blocks: Utilities.formatDate(); date comparison; setValues(); triggers.

Practical use cases

Team deadlines, assignments and personal chores.

Prerequisites

  • Comparing dates.
  • Interactive Learning Mode: a modern browser. Nothing else.
  • Real Workspace Build: a Google account.

Source data

Starter data: tab "Tasks" (fictional)
TaskOwnerDueStatus
SlidesAlex2026-11-20Open
BudgetJamie2026-12-05Open
ReviewSam2026-11-19Done

Setup in your own Google account

  1. Download 13-automated-task-management-system.zip (Code.gs, starter.csv, README).
  2. In Google Drive, create a lesson folder and a new Google Sheets file inside it.
  3. Rename the first tab to exactly Tasks, then File → Import → Upload starter.csv → Replace current sheet.
  4. Extensions → Apps Script. Replace Code.gs with the downloaded file. Save.
  5. Reload the spreadsheet, choose Workshop → Run application and authorize when asked.
  6. Check the result: Slides Overdue; Budget Open; Review Done.

Folder strategy: the repository's V6 code uses the folder that contains the spreadsheet. The deck mentions a Workshop Info cell B2; V6 never reads it. See the discrepancy log.

Complete source code (Code.gs)

From 13-automated-task-management-system at commit 4a26d919, SHA-256 dd87cab2d592. Unchanged.

// Automated Task Management System
// Entry point: updateTasks; source data stays intact unless explicitly noted.
function onOpen(){SpreadsheetApp.getUi().createMenu("Workshop").addItem("Run application","updateTasks").addItem("Install daily trigger","installDaily").addToUi();}
function updateTasks(){
// Fixed date makes workshop tests reproducible.
markTasks('2026-11-25');
}
function input(name) { const s=workshopSpreadsheet().getSheetByName(name); if(!s) throw Error('Missing tab: '+name); return s.getDataRange().getValues().slice(1).filter(r=>r.some(v=>v!=='')); }
function output(name,headers,rows) { const ss=workshopSpreadsheet(); const s=ss.getSheetByName(name)||ss.insertSheet(name); s.clearContents(); s.getRange(1,1,1,headers.length).setValues([headers]).setFontWeight('bold'); if(rows.length) s.getRange(2,1,rows.length,headers.length).setValues(rows.map(r=>r.map(v=>typeof v==='string' && /^[=+@-]/.test(v)?"'"+v:v))); s.setFrozenRows(1); return s; }
function day(v){return v instanceof Date?Utilities.formatDate(v,workshopSpreadsheet().getSpreadsheetTimeZone(),'yyyy-MM-dd'):String(v).slice(0,10);}
function markTasks(today){output('Priority',['Task','Owner','Due','Status','Priority'],input('Tasks').map(r=>[...r,r[3]==='Done'?'Done':day(r[2])<today?'Overdue':'Open']));}
function updateToday(){markTasks(day(new Date()));}
function installDaily(){PropertiesService.getScriptProperties().setProperty("WORKSHOP_TRIGGER_SHEET",SpreadsheetApp.getActiveSpreadsheet().getId());if(!ScriptApp.getProjectTriggers().some(t=>t.getHandlerFunction()==='updateToday'))ScriptApp.newTrigger('updateToday').timeBased().everyDays(1).create();}

function workshopSpreadsheet(){const active=SpreadsheetApp.getActiveSpreadsheet(); if(active)return active; const id=PropertiesService.getScriptProperties().getProperty("WORKSHOP_TRIGGER_SHEET"); if(!id)throw new Error("Run Install daily trigger from your copied spreadsheet first."); return SpreadsheetApp.openById(id);}

How the code works

Beginner explanation

updateTasks() writes a Priority tab: Done tasks stay Done, tasks due before the workshop date are Overdue, and the rest are Open. The fixed date makes everyone's results match during the workshop.

Technical explanation

markTasks(today) appends a computed priority to each row. day() turns Date cells into yyyy-MM-dd strings, which compare correctly as text. updateToday() uses the real date and is what the installed trigger calls. workshopSpreadsheet() supplies the spreadsheet in trigger context.

Slide excerpt

This is the excerpt shown on the workshop slide. It is a fragment and cannot run on its own.

function updateTasks(){
// Fixed date makes workshop tests reproducible.
markTasks('2026-11-25');
}

Common mistakes

  • Comparing Date objects with strings.
  • Using the real date in tests, so results change every day.
  • Installing a trigger that calls a function needing the UI.

Run it and expected output

Choose Workshop → Run application (runs updateTasks()). Expected: Slides Overdue; Budget Open; Review Done.

Original workshop exercise

Mark Slides Done; its priority becomes Done.

Troubleshooting and debugging

"done" in lower case

Review was marked "done" instead of "Done" and now shows Overdue.

Fix: Use the exact status Done; add a dropdown to prevent variants.

Exact string comparisons are strict. Data validation lists are the simplest prevention.

The trigger cannot find its spreadsheet

A simulated daily trigger runs updateToday() but the spreadsheet ID was never stored.

Fix: Install the trigger from the copied spreadsheet so its ID is stored.

Background runs have no user interface and no active file. Design for that context explicitly.

Extension activity: Configurable reference date and a dashboard

Read the reference date from an optional Settings tab (B2) instead of the fixed 2026-11-25, and add a Task Dashboard with counts per priority.

Acceptance checks:

  • Default reference date gives the baseline priorities
  • Settings date 2026-11-18 makes Slides Open

Original improvement idea from the workshop: Add a dashboard and configurable reference date.

Extension prompt
Update the existing app without removing working features. Add a dashboard and configurable reference date. Return complete updated files, explain changes and give regression tests.
Automation option: Existing Install daily trigger invokes updateToday using current date. Keep this separate from the baseline exercise.

Automation considerations

Rerun-safe: Priority is replaced. The daily trigger calls updateToday() with the real date and opens the stored spreadsheet ID.

Workshop note: Install daily trigger from your own copied spreadsheet; the installer stores its ID for background execution.

Build prompt from the workshop

Act as a Google Apps Script tutor. Build a container-bound Sheets app for lesson 13: Automated Task Management System. Input tab Tasks, exact headers: Task, Owner, Due, Status. Create updateTasks() with a fixed demo reference date 2026-11-25; compare date-only values, write Overdue/Open/Done to a Priority column; optional daily trigger uses current date in spreadsheet timezone. Do not depend on Workshop Info or the Workshop Index. Provide complete copy-paste Code.gs (and HTML if required), exact setup/run steps, explain the main code blocks, and include a test matching this expected outcome: Slides Overdue; Budget Open; Review Done. Preserve starter data, use batch operations where appropriate, handle errors, and never send email or delete files. For AI lessons use the supplied callGemini helper, treat input as untrusted, and validate outputs.
Match the reference entry point updateTasks and its output behavior. Reference: https://github.com/lsvekis/Google-Apps-Script-Workshop/tree/main/13-automated-task-management-system. Base version limitations: Workshop run uses fixed date; background access must be tested. For scheduled execution, save the current spreadsheet ID when installing the trigger and use openById when no active spreadsheet exists. Reinstall in each copy.

Knowledge check

  1. Why does updateTasks() use a fixed date?

    1. So workshop results are reproducible for everyone
    2. Apps Script cannot read today's date
    3. Triggers require it
    Answer

    So workshop results are reproducible for everyone Correct: tests need stable inputs.

  2. Why can yyyy-MM-dd strings be compared with < ?

    1. Their character order matches date order
    2. JavaScript converts them to dates
    3. It is a coincidence that fails often
    Answer

    Their character order matches date order Correct: year, month and day are zero-padded from most to least significant.

  3. Which function does the daily trigger call?

    1. updateToday
    2. updateTasks
    3. onOpen
    Answer

    updateToday Correct: installDaily() registers updateToday().

  4. Review is Done but shows Overdue. First check?

    1. The exact spelling and case of the status
    2. The trigger
    3. The time zone
    Answer

    The exact spelling and case of the status Correct: the comparison is case-sensitive.

  5. Should the daily trigger also email every overdue owner?

    1. Not yet: start with drafts or a summary and avoid repeating the same reminder daily
    2. Yes, every day
    3. Yes, from a custom function
    Answer

    Not yet: start with drafts or a summary and avoid repeating the same reminder daily Correct: notifications need duplicate prevention and review.

Five-minute presenter demonstration

Open the demo link (temporary workspace; saved learner work is not touched).

Opening hook: Raise your hand if you have ever done this by hand: Overdue tasks get lost in a long list. Let us make the spreadsheet do it.

  1. 0:00–0:45 — Problem and input. Show the Workspace view, Sheets service. Point at the Tasks tab and its headers: Task, Owner, Due, Status. Say what goes in and what should come out.
    Narration: Overdue tasks get lost in a long list. Practical uses: Team deadlines, assignments and personal chores.
  2. 0:45–1:30 — Predict and run. Ask the room: With the workshop date 2026-11-25, what priority will Slides (due 2026-11-20, Open) get? Click ▶ Run application (the same as Workshop → Run application). Open Trace to show each step the code took.
    Narration: Expected: Slides Overdue; Budget Open; Review Done.
  3. 1:30–3:00 — Explain the code. Click the Code tab. Select updateTasks() in the function list; read what it reads, writes and calls. Switch Beginner / Technical as needed.
    Narration: updateTasks() writes a Priority tab: Done tasks stay Done, tasks due before the workshop date are Overdue, and the rest are Open. The fixed date makes everyone's results match during the workshop.
  4. 3:00–4:15 — Change one input and rerun. Back to the Workspace tab. Select the Tasks tab, click cell D2, type Done in the formula bar and press Enter. Click ▶ Run application again.
    Narration: Workshop challenge: Mark Slides Done; its priority becomes Done.
  5. 4:15–5:00 — Verify and discuss automation. Click Check result. Discuss: Rerun-safe: Priority is replaced. The daily trigger calls updateToday() with the real date and opens the stored spreadsheet ID.
    Narration: Baseline limitation: Workshop run uses fixed date; background access must be tested.

Closing takeaway: markTasks preserves source rows and derives priority using status and ISO date comparison.

Related resources