National Commerce Docs
n8n flows

Notify: PO Line Item Discrepancy

Emails the account's NC staff once per closed PO, listing every line item received short or over.

When a purchase order closes with PO line items whose received quantity does not match what was ordered, this flow sends the account's NC staff one email for the whole PO. The email lists every discrepant line. It respects per-user preferences, never emails Client Users, and sends at most once per PO.

At a glance

  • Status: Active
  • Trigger: Webhook (POST /webhook/fa4e35de-c6fe-4ac3-bc89-8af1d30442ff), responds immediately. The payload is { "po_id": <PO record id> }.
  • Runs on: The Purchase Order Update Handler calling it after it has written every line item of a closed PO. The database only flags a line once the PO is closed, see When a discrepancy is flagged.
  • Talks to: Supabase (PO Line Items, POs, Brands, userRoles, user_settings, Auth Admin API); Gmail.

How it works

  1. The webhook receives the PO id.
  2. Get Discrepant Line Items loads every line on the PO with discrepancy_detected = true. If there are none, the flow stops and nothing is sent.
  3. Build Discrepancy Rows turns the lines into one table: SKU (shiphero_sku), description (purchase_order_line_item_name), ordered, received, and Short N or Over N.
  4. Claim PO Notification sets discrepancy_notification_sent on the PO, but only if the PO is 'closed' and the flag is still false. If no row is updated, the PO was already emailed and the flow stops.
  5. It resolves the PO's brand and the brand's users. Get Users For Brand keeps active rows only and skips Client Users (roleId is not the Client User role). Loop Over Users checks send_notifications and inventory_management.inbound_pos_issues (the Receiving Discrepancy Notification setting in Notification Settings), and each opted-in user gets one branded HTML Gmail alert with the table, linking to the receiving-discrepancies page.

Notes

  • Sends at most one email per PO per user. The claim is a single database update, so two runs for the same PO cannot both send.
  • Opt-in gated on two preference flags.
  • Client Users are filtered out when recipients are picked, so a stored preference can't turn the email on for them.
  • The SKU and description come straight from the line item, so a line whose SKU has not been classified yet is still listed.
  • The flag is set before sending and is never reset. A quantity that changes after the email has gone out produces no follow-up.
  • The line item's own discrepancy_notification_sent column is legacy. This flow no longer reads or writes it.

On this page