Skip to content

saveCreditRecordTool - Francis

A utility workflow that saves or updates credit tracking records in a PostgreSQL database. This workflow handles the complex business logic of tracking credit given, recovered amounts, and customer progress through various credit management stages.

Purpose

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

How It Works

  1. Receives Input Data: The workflow is triggered by another workflow with comprehensive credit tracking data including customer information, amounts, and micro-action details
  2. Upserts Credit Record: Performs a sophisticated database operation that either inserts a new credit record or updates an existing one based on phone number
  3. Calculates Running Totals: Automatically computes total credit locked (baseline + given - recovered) and weekly recovery progress
  4. Returns Summary: Provides a formatted output showing the current credit status and 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 run independently. It accepts 18 input parameters covering all aspects of credit tracking.

Nodes Used

Node Type Purpose
When Executed by Another Workflow Execute Workflow Trigger Receives input parameters from calling workflow
upsertCreditRecord PostgreSQL Inserts new or updates existing credit tracking record with complex business logic
setOutput Set Formats a human-readable summary of the operation results

External Services & Credentials Required

  • PostgreSQL Database: Requires connection to a database with a creditTracking table
    • Credential name: kdpTables
    • Must have read/write permissions on the creditTracking table

Environment Variables

No environment variables are used in this workflow.

Data Flow

Input Parameters

  • phoneNumber (string): Customer identifier
  • creditCustomersCount (number): Number of credit customers
  • totalCreditBaseline (number): Base credit amount
  • creditCustomerTypes (string): Types of credit customers
  • creditTypicalDays (number): Typical credit duration
  • weeklyRecoveryTarget (number): Target recovery amount per week
  • 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 used 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 if applicable
  • weekNumber (number): Current week number

Output

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

Error Handling

This workflow relies on PostgreSQL's built-in error handling. Database constraint violations or connection issues will cause the workflow to fail with appropriate error messages.

Known Limitations

  • Workflow is inactive and must be activated before use
  • Requires exact parameter names and types as specified
  • Database schema must match the expected creditTracking table structure
  • No input validation beyond database constraints

This is a utility workflow designed to be called by other credit management workflows. The calling workflow must provide all required parameters.

Setup Instructions

  1. Import Workflow: Import the JSON into your n8n instance
  2. Configure Database Credential:
    • Create a PostgreSQL credential named kdpTables
    • Ensure it has access to a database with the creditTracking table
  3. Verify Table Schema: Ensure your creditTracking table has all required columns:
    • phoneNumber, creditCustomersCount, totalCreditBaseline, creditCustomerTypes
    • creditTypicalDays, weeklyRecoveryTarget, targetCustomers
    • creditGivenToday, creditRecoveredToday, microActionType, microActionScript
    • microActionDate, microActionAttempted, microActionOutcome, amountRecovered
    • nextAction, creditModuleStage, creditSkipReason, weekNumber
    • totalCreditLocked, weeklyRecoveredSoFar, creditModuleActive, updatedAt
  4. Activate Workflow: Enable the workflow in n8n
  5. Test Integration: Call from another workflow with sample data to verify functionality