🔬 Detect procurement workflow gaps with Google Sheets, OpenAI, and Gmail

⚡ 2 views · 🔬 Document Extraction & Analysis

Description

Quick overview

This workflow watches procurement events in Google Sheets, validates and normalizes each entry, checks the procurement’s lifecycle state to detect missing required steps, and then uses OpenAI to recommend a recovery action, logs results back to Google Sheets, and notifies stakeholders via Gmail.

How it works

  1. Triggers every minute when a new or updated row appears in the “Procurement Events” Google Sheets tab.
  2. Normalizes key fields (IDs, event type/status, timestamps, amount, currency, and email addresses) and stops early by writing an error result back to Google Sheets if required fields are missing.
  3. Looks up the current procurement’s workflow state in the “Workflow State” sheet and loads the required lifecycle steps from the “Procurement Steps” sheet.
  4. Compares completed steps (including the current event) with required steps to identify missing steps and determine whether a workflow gap exists.
  5. If a gap is detected, logs the gap to the “Gap Log” sheet and sends the gap context to OpenAI to generate a structured recovery recommendation.
  6. Validates the OpenAI response and routes it to either a recovery task or a manual review task, writing the result to the “Workflow Results” sheet.
  7. Sends a Gmail notification to the requester with the missing step and recommended action so the procurement workflow can be corrected.

Setup

  1. Create and populate a Google Sheets spreadsheet with tabs and columns that match the workflow’s configuration: “Procurement Events”, “Workflow State”, “Procurement Steps”, “Gap Log”, and “Workflow Results”.
  2. Add Google Sheets credentials in n8n and update the spreadsheet ID and sheet/tab selections in all Google Sheets nodes to point to your document.
  3. Add an OpenAI API credential and confirm the selected model (gpt-4.1-nano) is available for your account.
  4. Add a Gmail credential with permission to send email, and ensure your input rows include a valid requester_email value for notifications.

Additional info

Troubleshooting Guide

IssuePossible CauseSolution
Procurement event does not enter the workflowGoogle Sheets Trigger is not configured correctly or the workflow is inactiveVerify the Google Sheets Trigger configuration and make sure the n8n workflow is active
Event is rejected as invalidevent_id, procurement_id, or event_type is emptyCheck the Procurement Events sheet and provide all three required fields
Workflow state is not retrievedNo matching procurement_id exists in Workflow StateAdd or update the corresponding procurement workflow state record
No lifecycle steps are detectedProcurement Steps does not contain valid required stepsVerify step_key, step_name, step_order, owner_role, success_event_type, and required values
A lifecycle step is ignoredThe step does not have required = yesUpdate the required field in Procurement Steps
AI recommendation failsOpenAI credential, model configuration, or response format is invalidVerify the OpenAI credential, selected model, and AI node configuration
AI response is treated as manual reviewThe AI response is not valid JSON or contains an unsupported actionReview the AI prompt and response structure
Recovery route is unsupportedThe missing step does not exist in the supported recovery route configurationAdd the required recovery step to the allowedSteps object or use manual review
Recovery task is not createdRecovery route validation did not return a valid routeReview route_status, missing_step_key, and the supported recovery routes
Manual-review task is created unexpectedlyAI response failed validation or the recovery step is unsupportedReview the recommendation and route-validation output
Email is not sentGmail credential or requester email is unavailableVerify the Gmail credential and the requester_email value
Email goes to the wrong recipientThe requester email in the procurement event is incorrectVerify requester_email in Procurement Events
Workflow results are missingThe relevant Google Sheets node cannot write to Workflow ResultsVerify Google credentials, sheet access, and column mappings
Gap Log is not updatedGap logging node cannot access or write to the Gap Log sheetVerify the spreadsheet, sheet name, credentials, and column mappings
Procurement state appears incorrectWorkflow State data does not match the procurement ID or contains unexpected valuesReview the Workflow State record and completed-step information
Amount is incorrectAmount is converted using the JavaScript Number() conversionVerify that the source amount contains a valid numeric value
Currency defaults unexpectedlyCurrency is empty in the source eventProvide the required currency value in Procurement Events
Notification status remains pendingThe workflow result is created before notification completionCheck the Gmail node execution and downstream workflow execution status

đź”— Nodes Used

Google Sheets, Gmail, Google Sheets Trigger, OpenAI

📥 Import

Download workflow.json and import into n8n: Workflow menu → Import from File

📖 Importing guide · 🔑 Credential setup