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¶
-
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.
-
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.
-
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 recordcreditCustomersCount(number): Number of customers receiving credittotalCreditBaseline(number): Base credit amountcreditCustomerTypes(string): Types of credit customerscreditTypicalDays(number): Typical credit duration in daysweeklyRecoveryTarget(number): Target amount to recover weeklytargetCustomers(number): Target number of customerscreditGivenToday(number): Credit amount given todaycreditRecoveredToday(number): Credit amount recovered todaymicroActionType(string): Type of micro-action takenmicroActionScript(string): Script or description of micro-actionmicroActionAttempted(boolean): Whether micro-action was attemptedmicroActionOutcome(string): Result of micro-actionamountRecovered(number): Specific amount recoverednextAction(string): Planned next actioncreditModuleStage(string): Current stage in credit modulecreditSkipReason(string): Reason for skipping actionsweekNumber(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
Related Workflows¶
This workflow is designed to be called by other workflows but no specific related workflows are identified in the current configuration.
Setup Instructions¶
-
Import Workflow: Import the workflow JSON into your n8n instance
-
Configure Database Credentials:
- Create PostgreSQL credentials named "kdpTestEnv"
- Ensure connection to database with "creditTracking" table
- Test database connectivity
-
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)
-
Test Execution: Create a test workflow that calls this workflow with sample data to verify proper operation
-
Activate Workflow: Activate the workflow to make it available for execution by other workflows