A while back I asked here how to show each company's last invoice date and amount from QuickBooks-synced invoices. Thanks to everyone who replied. Here's what I ended up building, in case it helps someone.
Why the native options didn't work:
- Rollups can return the latest invoice date, but conditions don't support date fields (so no "dated today or earlier"), and there's no "amount of the latest record" rollup.
- Invoice-based workflows don't offer Edit record or Copy property value, so they can't write to the associated company.
- Copying from "most recently created" invoice ≠ latest invoice date (backfills and future-dated invoices break it).
What worked: a daily company-based workflow (enrolls only companies with at least one invoice) with a custom code step:
- Get the company's associated invoice IDs (v4 associations, paginated)
- Batch-read invoice date, status, amount billed, number and create date
- Filter: date ≤ today in the portal's time zone, not draft/voided, not on a small exclusion list
- Pick the latest date (ties → most recently created)
- Return found / date / amount / number → branch → Edit record
Running it daily means it recalculates from all invoices every time, so the first run backfills everything (no import needed), and future-dated invoices get picked up when their date arrives.
Gotchas:
- Private apps are now "legacy." You create a service key instead (read-only scopes for invoices and companies) and store it as a secret.
- The new code template returns { outputFields }; my older callback version threw "callback is not a function."
- The workflow Test button didn't write anything for me. The custom code action's own Test action is what showed real outputs and errors.
- Branch on an explicit "no" to clear fields, not "None met," or an error run will wipe good values.
- Log the raw date. Invoice dates came through as T04:00:00Z (midnight US Eastern), which looked a day off until I printed it.
Also: the minimap panel in the workflow editor makes checking a branchy workflow way easier, if you haven't used it.
Happy to share the code structure if anyone's doing something similar.