saveCreditRecordTool - Francis¶
This workflow manages credit tracking records for business owners by storing and updating comprehensive credit information 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.
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 micro-action details.
-
Updates Database Record: Executes a sophisticated PostgreSQL upsert operation that either creates a new credit tracking record or updates an existing one based on the phone number.
-
Calculates Financial Metrics: The database operation automatically calculates running totals for locked credit amounts and weekly recovery progress based on daily credit given and recovered amounts.
-
Returns Summary: Provides a formatted output message 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, accepting 18 different input parameters related to credit tracking and management.
Nodes Used¶
| Node Type | Node Name | Purpose |
|---|---|---|
| Execute Workflow Trigger | When Executed by Another Workflow | Receives credit tracking data from calling workflows |
| PostgreSQL | upsertCreditRecord | Performs complex database upsert with financial calculations |
| Set | setOutput | Formats and returns a summary of the credit record status |
External Services & Credentials Required¶
- PostgreSQL Database: Requires connection to a Supabase-hosted PostgreSQL instance
- Credential: "PostgresOnSupabase"
- Access needed: Read/Write permissions on
creditTrackingtable
Environment Variables¶
No environment variables are directly used in this workflow. All configuration is handled through the PostgreSQL credential connection.
Data Flow¶
Input Parameters (18 fields):¶
phoneNumber(string): Unique identifier for the credit recordcreditCustomersCount(number): Number of customers receiving credittotalCreditBaseline(number): Base credit amountcreditCustomerTypes(string): Types of customers receiving creditcreditTypicalDays(number): Typical credit duration in daysweeklyRecoveryTarget(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 or description of micro-actionmicroActionAttempted(boolean): Whether micro-action was attemptedmicroActionOutcome(string): Result of the micro-actionamountRecovered(number): Amount recovered from micro-actionnextAction(string): Planned next actioncreditModuleStage(string): Current stage in credit modulecreditSkipReason(string): Reason for skipping credit activitiesweekNumber(number): Current week number in tracking cycle
Output:¶
output(string): Formatted status message showing total credit locked, weekly recovery progress, and current module stage
Error Handling¶
The workflow uses PostgreSQL's built-in error handling. The COALESCE functions in the upsert query ensure that NULL values don't overwrite existing data. The GREATEST function prevents negative credit amounts.
Known Limitations¶
No specific limitations documented in the provided context.
Related Workflows¶
This workflow is designed to be called by other workflows in the credit management system, but no specific related workflows are identified in the current context.
Setup Instructions¶
-
Import the Workflow:
- Copy the workflow JSON and import it into your n8n instance
-
Configure Database Connection:
- Set up a PostgreSQL credential named "PostgresOnSupabase"
- Ensure connection to your Supabase PostgreSQL instance
- Verify the
creditTrackingtable exists with all required columns
-
Database Schema Requirements: The workflow expects a
creditTrackingtable with these columns:phoneNumber(TEXT, PRIMARY KEY)creditCustomersCount,totalCreditBaseline,creditTypicalDays,weeklyRecoveryTarget,targetCustomers,creditGivenToday,creditRecoveredToday,amountRecovered,weekNumber(NUMERIC)creditCustomerTypes,microActionType,microActionScript,microActionOutcome,nextAction,creditModuleStage,creditSkipReason(TEXT)microActionDate(DATE)microActionAttempted,creditModuleActive(BOOLEAN)totalCreditLocked,weeklyRecoveredSoFar(NUMERIC)updatedAt(TIMESTAMP)
-
Test the Workflow:
- Call this workflow from another workflow with sample credit data
- Verify that records are created/updated correctly in the database
- Check that the output message formats correctly
-
Integration:
- Configure other workflows to call this workflow using the Execute Workflow node
- Ensure all 18 required parameters are passed from calling workflows