Quick overview
This workflow runs on a schedule (or manually) to read invoices and purchase orders from Google Sheets, validate each invoice with a three-way match against the PO register, and then log the decision and send approval/exception emails via Gmail using a safe test mode.
How it works
- Runs on weekdays at 09:00 (or on manual trigger) and loads configuration values like approval limits, allowed currencies, and test email routing.
- Reads the "Invoice Queue" and "PO Register" tabs from Google Sheets and combines the rows into a single dataset.
- Validates each invoice for required fields, duplicate vendor/invoice-number keys, supported currency, and matches it to an approved PO with vendor, currency, and amount tolerance checks.
- Classifies each invoice as AUTO_APPROVE, NEED_APPROVAL, or EXCEPTION and generates a decision reason plus an idempotency key.
- Appends the decision to the "AP Decision Log" in Google Sheets before sending any notifications.
- Sends NEED_APPROVAL and EXCEPTION emails via Gmail to the configured test recipient and appends a full audit entry (including exception counts) to the decision log.
Setup
- Create a Google Sheets file with three tabs named "Invoice Queue", "PO Register", and "AP Decision Log" and ensure invoices include fields like InvoiceID, InvoiceNumber, VendorName, PONumber, InvoiceAmount, and Currency.
- Add Google Sheets OAuth2 credentials and replace SET_SPREADSHEET_ID in the configuration with your spreadsheet ID.
- Add Gmail OAuth2 credentials and replace SET_TEST_EMAIL (and optionally SET_AP_EMAIL) in the configuration with your recipient addresses.
- Review the configuration values (approvalLimit, amountTolerance, allowedCurrencies) and keep testMode enabled while validating with sample data before using it operationally.