Skip to content

saveCreditRecordTool - Francis

This workflow provides a centralized tool for saving and updating credit tracking records in a PostgreSQL database. It handles the complete lifecycle of credit data including customer counts, baseline amounts, recovery targets, and micro-action tracking with intelligent upsert logic that maintains data integrity while allowing for incremental updates.

Purpose

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

How It Works

  1. Receives Credit Data: The workflow is triggered by another workflow with comprehensive credit tracking parameters including customer information, financial metrics, and action details
  2. Upserts Database Record: Executes a sophisticated PostgreSQL query that either inserts a new credit record or updates an existing one based on phone number, with intelligent field merging and calculated totals
  3. Returns Confirmation: Formats and returns a summary message showing the updated credit status including total locked credit, weekly recovery progress, and current module stage

Mermaid 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 input parameters covering all aspects of credit tracking from customer demographics to action outcomes.

Nodes Used

Node Type Purpose
When Executed by Another Workflow Execute Workflow Trigger Receives credit tracking data from calling workflows with 18 input parameters
upsertCreditRecord PostgreSQL Performs complex upsert operation on creditTracking table with calculated fields and conflict resolution
setOutput Set Formats a human-readable confirmation message with key credit metrics

External Services & Credentials Required

  • PostgreSQL Database: Requires "PostgresOnSupabase" credential for database access
    • Must have access to creditTracking table with appropriate schema
    • Needs INSERT and UPDATE permissions

Environment Variables

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

Data Flow

Input Parameters: - phoneNumber (string): Primary identifier for the credit record - creditCustomersCount (number): Number of customers receiving credit - totalCreditBaseline (number): Baseline credit amount - creditCustomerTypes (string): Types of credit customers - creditTypicalDays (number): Typical credit duration in days - 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 performed - 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 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 confirmation message including total credit locked, weekly recovery progress, and current module stage

Error Handling

This workflow relies on PostgreSQL's built-in error handling. Database connection failures or constraint violations will cause the workflow to fail. The upsert query uses ON CONFLICT to handle duplicate phone numbers gracefully.

Known Limitations

  • No input validation is performed on the parameters
  • Database errors are not caught or handled gracefully
  • The workflow assumes the creditTracking table schema exists and matches the expected structure
  • No logging or audit trail beyond database timestamps

This workflow is designed to be called by other workflows in the credit management system. Look for workflows that handle credit assessment, recovery actions, or customer interactions.

Setup Instructions

  1. Import the Workflow: Import the JSON into your n8n instance
  2. Configure Database Credential:
    • Create a PostgreSQL credential named "PostgresOnSupabase"
    • Ensure it has access to the creditTracking table
  3. Verify Database Schema: Ensure your PostgreSQL database has a creditTracking table with all required columns
  4. Test the Workflow: Call it from another workflow with sample data to verify the database connection and upsert logic
  5. Integration: Reference this workflow from other workflows using the Execute Workflow node with the required 18 parameters

The workflow is currently inactive and should be activated once properly configured and tested.