Skip to content

saveCreditRecordTool - Francis_testing

A utility workflow that manages credit tracking records for business owners by storing and updating comprehensive credit management data including customer counts, recovery targets, micro-actions, and financial metrics in a PostgreSQL database.

Purpose

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

This workflow appears to be designed for tracking and managing credit operations for small business owners, capturing detailed information about credit customers, recovery targets, daily transactions, and micro-actions taken to improve credit management practices.

How It Works

  1. Receives Credit Data: The workflow is triggered by another workflow with comprehensive credit tracking information including phone number, customer counts, financial baselines, and action details.

  2. Upserts Database Record: Executes a sophisticated PostgreSQL query that either inserts a new credit tracking record or updates an existing one based on the phone number, calculating running totals for locked credit and weekly recovery amounts.

  3. Returns Summary: Formats and returns a human-readable summary showing the current credit status including total locked credit, 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 within the same n8n instance. It accepts 18 different input parameters covering all aspects of credit tracking from basic customer information to specific micro-action details.

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 tracking records with complex financial calculations
setOutput Set Formats a summary message with key credit metrics

External Services & Credentials Required

  • PostgreSQL Database: Requires connection to a PostgreSQL database with credentials named "kdpTestEnv"
    • Database must contain a "creditTracking" table with appropriate schema
    • Credentials should include: host, port, database name, username, and password

Environment Variables

No environment variables are used in this workflow. All configuration is handled through n8n credentials and direct node parameters.

Data Flow

Input Parameters

  • phoneNumber (string): Unique identifier for the credit tracking record
  • creditCustomersCount (number): Number of customers receiving credit
  • totalCreditBaseline (number): Base credit amount
  • creditCustomerTypes (string): Types of credit customers
  • creditTypicalDays (number): Typical credit duration in days
  • weeklyRecoveryTarget (number): Target amount to recover weekly
  • targetCustomers (number): Target number of customers
  • creditGivenToday (number): Credit amount given today
  • creditRecoveredToday (number): Credit amount recovered today
  • microActionType (string): Type of micro-action taken
  • microActionScript (string): Script or description of micro-action
  • microActionAttempted (boolean): Whether micro-action was attempted
  • microActionOutcome (string): Result of micro-action
  • amountRecovered (number): Specific amount recovered
  • nextAction (string): Planned next action
  • creditModuleStage (string): Current stage in credit module
  • creditSkipReason (string): Reason for skipping actions
  • weekNumber (number): Current week number

Output

  • output (string): Formatted summary message containing:
    • Total credit locked amount in KES
    • Weekly recovered amount in KES
    • Current credit module stage

Error Handling

This workflow does not implement explicit error handling. Database errors from the PostgreSQL node would cause the workflow to fail and stop execution. Consider adding error handling nodes for production use.

Known Limitations

  • No validation of input parameters before database insertion
  • No error handling for database connection failures
  • Hard-coded currency (KES) in output message
  • Relies on external workflow for data validation
  • No logging or audit trail beyond database timestamps

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

Setup Instructions

  1. Import Workflow: Import the workflow JSON into your n8n instance

  2. Configure Database Credentials:

    • Create PostgreSQL credentials named "kdpTestEnv"
    • Ensure connection to database with "creditTracking" table
    • Test database connectivity
  3. Database Schema: Ensure your PostgreSQL database has a "creditTracking" table with the following columns:

    • phoneNumber (TEXT, PRIMARY KEY)
    • creditCustomersCount (INTEGER)
    • totalCreditBaseline (NUMERIC)
    • creditCustomerTypes (TEXT)
    • creditTypicalDays (INTEGER)
    • weeklyRecoveryTarget (NUMERIC)
    • targetCustomers (INTEGER)
    • creditGivenToday (NUMERIC)
    • creditRecoveredToday (NUMERIC)
    • microActionType (TEXT)
    • microActionScript (TEXT)
    • microActionDate (DATE)
    • microActionAttempted (BOOLEAN)
    • microActionOutcome (TEXT)
    • amountRecovered (NUMERIC)
    • nextAction (TEXT)
    • creditModuleStage (TEXT)
    • creditSkipReason (TEXT)
    • weekNumber (INTEGER)
    • totalCreditLocked (NUMERIC)
    • weeklyRecoveredSoFar (NUMERIC)
    • creditModuleActive (BOOLEAN)
    • updatedAt (TIMESTAMP)
  4. Test Execution: Create a test workflow that calls this workflow with sample data to verify proper operation

  5. Activate Workflow: Activate the workflow to make it available for execution by other workflows