Hands-On AI WorkshopHomeProjectsLearnResourcesPresenterHelpProgress

Project 26 of 30 · Pathway 6 — Everyday Automation

Travel Itinerary and Budget Planner

Travel costs are scattered across bookings. Sort itinerary and calculate daily and overall costs.

Real-world benefit
Weekend trips, family vacations and business travel.
Technologies
Google Sheets, Sorting, Grouping
Required knowledge
None.
Time and level
About 15 minutes · Beginner
AI requirement
None: deterministic Apps Script
Expected baseline
Day one 230; day two 20; total 250

Loading the interactive studio…

Introduction

Sort normalized dates; accumulate per-day costs; output two reports. The application's entry point is planTrip(). Baseline limitation, as stated in the workshop: No currency conversion or booking integration.

Key building blocks: getValues(); JavaScript transformations; setValues(); validation and calculations.

Practical use cases

Weekend trips, family vacations and business travel.

Prerequisites

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

Source data

Starter data: tab "Trip" (fictional)
DateActivityCost
2026-12-01Train80
2026-12-01Hotel150
2026-12-02Museum20

Setup in your own Google account

  1. Download 26-travel-itinerary-and-budget-planner.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 Trip, 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: Day one 230; day two 20; total 250

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 26-travel-itinerary-and-budget-planner at commit 4a26d919, SHA-256 3f830b054af0. Unchanged.

// Travel Itinerary and Budget Planner
// Entry point: planTrip; source data stays intact unless explicitly noted.
function onOpen(){SpreadsheetApp.getUi().createMenu("Workshop").addItem("Run application","planTrip").addToUi();}
function planTrip(){
// Sort activities and aggregate costs by day.
const rows=input('Trip').map(r=>[day(r[0]),r[1],num(r[2])]).sort((a,b)=>a[0].localeCompare(b[0]));const m={};rows.forEach(r=>m[r[0]]=(m[r[0]]||0)+r[2]);output('Itinerary',['Date','Activity','Cost'],rows);output('Budget',['Date','Cost'],[...Object.entries(m),['Total',rows.reduce((a,r)=>a+r[2],0)]]);
}
function input(name) { const s=SpreadsheetApp.getActive().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=SpreadsheetApp.getActive(); 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 num(v){if(v===''||!Number.isFinite(Number(v))) throw Error('Invalid number: '+v); return Number(v);}
function day(v){return v instanceof Date?Utilities.formatDate(v,SpreadsheetApp.getActive().getSpreadsheetTimeZone(),'yyyy-MM-dd'):String(v).slice(0,10);}

How the code works

Beginner explanation

planTrip() sorts the trip by date into an Itinerary tab and adds up the cost of each day plus the whole trip in a Budget tab.

Technical explanation

Rows are mapped to [day(date), activity, num(cost)], sorted with localeCompare on the date string, grouped by date in an object and totalled with reduce(). There is no currency field and no booking integration in the baseline.

Slide excerpt

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

function planTrip(){
// Sort activities and aggregate costs by day.
const rows=input('Trip').map(r=>[day(r[0]),r[1],num(r[2])]).sort((a,b)=>a[0].localeCompare(b[0]));const m={};rows.forEach(r=>m[r[0]]=(m[r[0]]||0)+r[2]);output('Itinerary',['Date','Activity','Cost'],rows);output('Budget',['Date','Cost'],[...Object.entries(m),['Total',rows.reduce((a,r)=>a+r[2],0)]]);
}

Common mistakes

  • Summing costs in different currencies.
  • Implying the script books anything.
  • Sorting Date objects as strings without normalizing.

Run it and expected output

Choose Workshop → Run application (runs planTrip()). Expected: Day one 230; day two 20; total 250

Original workshop exercise

Change Museum cost to 30; day two 30 and overall 260.

Troubleshooting and debugging

A missing cost

The hotel cost is blank.

Fix: Enter the hotel cost (150).

A blank cost is unknown, not free.

A booking entered twice

Day one suddenly costs 380.

Fix: Remove the duplicate booking.

Aggregations magnify duplicate data. Add a booking reference column to detect it.

Extension activity: Daily limit and currency label

Read an optional Settings tab (Daily limit, Currency) and write a Budget Check tab with Over/OK per day. No currency conversion.

Acceptance checks:

  • No Settings: Budget unchanged and no Budget Check
  • Limit 200 CAD: day one Over, day two OK

Original improvement idea from the workshop: Add budget limit and currency fields

Extension prompt
Improve the existing application: Add budget limit and currency fields. Preserve working features and provide complete code and regression tests.
Automation option: Refresh when itinerary changes; avoid scheduled external bookings. Keep this separate from the baseline exercise.

Automation considerations

Rerun-safe. Refresh when the itinerary changes; never schedule external bookings.

Workshop note: Refresh when itinerary changes; avoid scheduled external bookings.

Build prompt from the workshop

Build a complete container-bound Apps Script app named Travel Itinerary and Budget Planner. Input tab Trip, headers Date|Activity|Cost. Implement planTrip() to sort itinerary and calculate daily and overall costs. Add a menu, preserve inputs, validate data, explain code and test against: Day one 230; day two 20; total 250. For AI use callGemini and treat input as data; never send email.
Match the reference entry point planTrip and its output behavior. Reference: https://github.com/lsvekis/Google-Apps-Script-Workshop/tree/main/26-travel-itinerary-and-budget-planner. Base version limitations: No currency conversion or booking integration.

Knowledge check

  1. How are days grouped?

    1. By the yyyy-MM-dd date string
    2. By activity
    3. By cost
    Answer

    By the yyyy-MM-dd date string Correct.

  2. Does the baseline convert currencies?

    1. No
    2. Yes, automatically
    3. Only to CAD
    Answer

    No Correct: costs are plain numbers.

  3. Itinerary order is by…

    1. Date
    2. Cost
    3. Name
    Answer

    Date Correct.

  4. Day one is 380 instead of 230. First check?

    1. Duplicate rows in Trip
    2. Gemini
    3. The time zone
    Answer

    Duplicate rows in Trip Correct.

  5. Should the planner book the hotel when the budget fits?

    1. No: bookings are external actions that need a person
    2. Yes
    3. Yes, with AI
    Answer

    No: bookings are external actions that need a person Correct.

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: Travel costs are scattered across bookings. Let us make the spreadsheet do it.

  1. 0:00–0:45 — Problem and input. Show the Workspace view, Sheets service. Point at the Trip tab and its headers: Date, Activity, Cost. Say what goes in and what should come out.
    Narration: Travel costs are scattered across bookings. Practical uses: Weekend trips, family vacations and business travel.
  2. 0:45–1:30 — Predict and run. Ask the room: What is the cost for day one (2026-12-01)? Click ▶ Run application (the same as Workshop → Run application). Open Trace to show each step the code took.
    Narration: Expected: Day one 230; day two 20; total 250
  3. 1:30–3:00 — Explain the code. Click the Code tab. Select planTrip() in the function list; read what it reads, writes and calls. Switch Beginner / Technical as needed.
    Narration: planTrip() sorts the trip by date into an Itinerary tab and adds up the cost of each day plus the whole trip in a Budget tab.
  4. 3:00–4:15 — Change one input and rerun. Back to the Workspace tab. Select the Trip tab, click cell C4, type 30 in the formula bar and press Enter. Click ▶ Run application again.
    Narration: Workshop challenge: Change Museum cost to 30; day two 30 and overall 260.
  5. 4:15–5:00 — Verify and discuss automation. Click Check result. Discuss: Rerun-safe. Refresh when the itinerary changes; never schedule external bookings.
    Narration: Baseline limitation: No currency conversion or booking integration.

Closing takeaway: Sort normalized dates; accumulate per-day costs; output two reports.

Related resources