saveCreditRecordTool - Francis¶
This workflow provides a centralized tool for saving and updating credit tracking records in a PostgreSQL database. It handles the complex logic of maintaining credit balances, recovery tracking, and micro-action logging for credit management operations.
Purpose¶
No business context provided yet — add a context.md to enrich this documentation.
How It Works¶
-
Receives Input: The workflow is triggered by another workflow with comprehensive credit tracking data including customer information, credit amounts, recovery targets, and micro-action details.
-
Database Upsert: Executes a sophisticated PostgreSQL query that either inserts a new credit record or updates an existing one based on the phone number. The query handles complex calculations for credit balances and recovery tracking.
-
Returns Summary: Formats and returns a human-readable summary of the saved record including total credit locked, 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 run independently. It accepts 18 different 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 workflows |
| upsertCreditRecord | PostgreSQL | Inserts or updates credit tracking records with complex business logic |
| setOutput | Set | Formats the response message with key credit metrics |
External Services & Credentials Required¶
- PostgreSQL Database: Requires connection to a PostgreSQL database (configured as "PostgresOnSupabase")
- Database must contain a
creditTrackingtable with appropriate schema - Credentials needed: host, port, database name, username, password
- Database must contain a
Environment Variables¶
No environment variables are used in this workflow. All configuration is handled through n8n credentials.
Data Flow¶
Input Parameters¶
phoneNumber(string): Customer identifiercreditCustomersCount(number): Number of credit customerstotalCreditBaseline(number): Baseline credit amountcreditCustomerTypes(string): Types of credit customerscreditTypicalDays(number): Typical credit durationweeklyRecoveryTarget(number): Target recovery amount per weektargetCustomers(number): Target customer countcreditGivenToday(number): Credit amount given todaycreditRecoveredToday(number): Credit amount recovered todaymicroActionType(string): Type of micro-action performedmicroActionScript(string): Script used for micro-actionmicroActionAttempted(boolean): Whether micro-action was attemptedmicroActionOutcome(string): Result of micro-actionamountRecovered(number): Amount recovered from actionnextAction(string): Planned next actioncreditModuleStage(string): Current stage in credit modulecreditSkipReason(string): Reason for skipping credit actionweekNumber(number): Current week number
Output¶
output(string): Formatted summary message containing:- Total credit locked amount
- Weekly recovery progress
- 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 return an error to the calling workflow.
Known Limitations¶
No specific limitations documented in the business context.
Related Workflows¶
No related workflows specified in the current context.
Setup Instructions¶
-
Import Workflow: Import the workflow JSON into your n8n instance.
-
Configure Database Credentials:
- Create a PostgreSQL credential named "PostgresOnSupabase"
- Configure connection details for your database
-
Database Schema: Ensure your PostgreSQL database has a
creditTrackingtable with the following columns:phoneNumber(primary key)creditCustomersCount,totalCreditBaseline,creditTypicalDays,weeklyRecoveryTarget,targetCustomers(numeric fields)creditCustomerTypes,microActionType,microActionScript,microActionOutcome,nextAction,creditModuleStage,creditSkipReason(text fields)creditGivenToday,creditRecoveredToday,amountRecovered,weekNumber,totalCreditLocked,weeklyRecoveredSoFar(numeric fields)microActionDate(date field)microActionAttempted,creditModuleActive(boolean fields)updatedAt(timestamp field)
-
Test Integration: Create a test workflow that calls this workflow with sample data to verify the integration works correctly.
-
Activate: The workflow is currently inactive - activate it when ready for production use.