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¶
- Receives Input Data: The workflow is triggered by another workflow with comprehensive credit tracking data including customer information, amounts, and micro-action details
- Upserts Credit Record: Performs a sophisticated database operation that either inserts a new credit record or updates an existing one based on phone number
- Calculates Running Totals: Automatically computes total credit locked (baseline + given - recovered) and weekly recovery progress
- 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
creditTrackingtable- Credential name:
kdpTables - Must have read/write permissions on the
creditTrackingtable
- Credential name:
Environment Variables¶
No environment variables are used in this workflow.
Data Flow¶
Input Parameters¶
phoneNumber(string): Customer identifiercreditCustomersCount(number): Number of credit customerstotalCreditBaseline(number): Base credit amountcreditCustomerTypes(string): Types of credit customerscreditTypicalDays(number): Typical credit durationweeklyRecoveryTarget(number): Target recovery amount per weektargetCustomers(number): Target number of customerscreditGivenToday(number): Credit amount given todaycreditRecoveredToday(number): Credit amount recovered todaymicroActionType(string): Type of micro-action takenmicroActionScript(string): Script used for micro-actionmicroActionAttempted(boolean): Whether micro-action was attemptedmicroActionOutcome(string): Result of micro-actionamountRecovered(number): Amount recovered from micro-actionnextAction(string): Next planned actioncreditModuleStage(string): Current stage in credit modulecreditSkipReason(string): Reason for skipping if applicableweekNumber(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
creditTrackingtable structure - No input validation beyond database constraints
Related Workflows¶
This is a utility workflow designed to be called by other credit management workflows. The calling workflow must provide all required parameters.
Setup Instructions¶
- Import Workflow: Import the JSON into your n8n instance
- Configure Database Credential:
- Create a PostgreSQL credential named
kdpTables - Ensure it has access to a database with the
creditTrackingtable
- Create a PostgreSQL credential named
- Verify Table Schema: Ensure your
creditTrackingtable has all required columns:phoneNumber,creditCustomersCount,totalCreditBaseline,creditCustomerTypescreditTypicalDays,weeklyRecoveryTarget,targetCustomerscreditGivenToday,creditRecoveredToday,microActionType,microActionScriptmicroActionDate,microActionAttempted,microActionOutcome,amountRecoverednextAction,creditModuleStage,creditSkipReason,weekNumbertotalCreditLocked,weeklyRecoveredSoFar,creditModuleActive,updatedAt
- Activate Workflow: Enable the workflow in n8n
- Test Integration: Call from another workflow with sample data to verify functionality