Skip to content

saveCreditRecordTool - Francis

A utility workflow that saves and updates credit tracking records for business owners, maintaining real-time visibility into credit given to customers, recovery progress, and micro-actions taken to improve credit collection.

Purpose

No business context provided yet — add a context.md to enrich this documentation.

Based on the workflow structure, this appears to be a credit management tool that helps business owners track: - Credit extended to customers - Daily credit recovery activities - Weekly recovery targets and progress - Micro-actions taken to improve credit collection - Overall credit module progression stages

How It Works

  1. Receive Credit Data: The workflow accepts comprehensive credit tracking information including customer counts, baseline amounts, recovery targets, and daily transactions
  2. Upsert Database Record: Performs a sophisticated database operation that either inserts a new credit record or updates an existing one, calculating running totals for locked credit and weekly recovery progress
  3. Return Summary: Provides a formatted response showing the current credit status including total locked amount, weekly recovery progress, and current module stage

Workflow Diagram

graph TD
    A[When Executed by Another Workflow] --> B[upsertCreditRecord]
    B --> C[setOutput]

Trigger

Execute Workflow Trigger: This workflow is designed to be called by other workflows, not triggered directly. It accepts 18 different input parameters related to credit tracking and management.

Nodes Used

Node Type Purpose
When Executed by Another Workflow Execute Workflow Trigger Receives credit tracking data from calling workflows
upsertCreditRecord PostgreSQL Inserts or updates credit records with complex calculations
setOutput Set Formats a summary response with key credit metrics

External Services & Credentials Required

  • PostgreSQL Database: Requires "PostgresOnSupabase" credential for database operations
    • Database must contain a creditTracking table with appropriate schema
    • Connection details needed: host, port, database name, username, password

Environment Variables

No environment variables are used in this workflow. All configuration is handled through the PostgreSQL credential.

Data Flow

Input Parameters

  • phoneNumber (string): Unique identifier for the business owner
  • creditCustomersCount (number): Number of customers with credit
  • totalCreditBaseline (number): Base credit amount
  • creditCustomerTypes (string): Types of credit customers
  • creditTypicalDays (number): Typical credit duration
  • weeklyRecoveryTarget (number): Weekly recovery goal
  • targetCustomers (number): Target customer count
  • creditGivenToday (number): Credit extended today
  • creditRecoveredToday (number): Credit recovered today
  • microActionType (string): Type of micro-action taken
  • microActionScript (string): Script for micro-action
  • microActionAttempted (boolean): Whether micro-action was attempted
  • microActionOutcome (string): Result of micro-action
  • amountRecovered (number): Amount recovered from micro-action
  • nextAction (string): Next planned action
  • creditModuleStage (string): Current stage in credit module
  • creditSkipReason (string): Reason for skipping actions
  • weekNumber (number): Current week number

Output

  • output (string): Formatted summary including total credit locked, weekly recovery progress, and current stage

Error Handling

The workflow uses PostgreSQL's built-in error handling. If the database operation fails, the workflow will stop and return an error. The upsert operation includes: - Conflict resolution using ON CONFLICT clause - COALESCE functions to handle null values gracefully - GREATEST function to ensure credit amounts don't go negative

Known Limitations

  • Requires existing creditTracking table with specific schema
  • No input validation - relies on calling workflow to provide correct data types
  • Limited error reporting - database errors may not be user-friendly
  • No rollback mechanism for failed operations

This workflow is designed to be called by other credit management workflows but no specific related workflows are identified in the current documentation.

Setup Instructions

  1. Import Workflow: Import the JSON into your n8n instance
  2. Configure Database Credential:
    • Create a PostgreSQL credential named "PostgresOnSupabase"
    • Configure connection to your Supabase or PostgreSQL instance
  3. Create Database Table: Ensure your database has a creditTracking table with columns matching the workflow's INSERT statement
  4. Test Connection: Run a test execution to verify database connectivity
  5. Integration: Call this workflow from other workflows using the Execute Workflow node, passing the required 18 parameters

The workflow is ready to use once the database credential is configured and the target table exists.