saveCreditRecordTool - Francis¶
This workflow provides a centralized tool for saving and updating credit tracking records in a PostgreSQL database. It handles both new credit record creation and updates to existing records, automatically calculating running totals for credit amounts and recovery progress while maintaining a complete audit trail of micro-actions and credit module stages.
Purpose¶
No business context provided yet — add a context.md to enrich this documentation.
How It Works¶
- Receives Input Data: The workflow accepts comprehensive credit tracking data including customer information, credit amounts, recovery targets, and micro-action details
- Upserts Credit Record: Executes a sophisticated PostgreSQL query that either inserts a new credit tracking record or updates an existing one based on phone number
- Calculates Running Totals: Automatically computes total credit locked and weekly recovery progress using the provided daily amounts
- Returns Summary: Provides a formatted output showing the current credit status including total locked amount, weekly recovery progress, and 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 and accepts 18 different input parameters including phone number, credit amounts, customer data, and micro-action tracking information.
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 calculations |
| setOutput | Set | Formats and returns a summary of the saved credit record |
External Services & Credentials Required¶
- PostgreSQL Database: Requires connection to a Supabase PostgreSQL instance
- Credential:
PostgresOnSupabase - Used for: Storing and updating credit tracking records
- Credential:
Environment Variables¶
No environment variables are used in this workflow. All configuration is handled through the PostgreSQL credential.
Data Flow¶
Input Parameters¶
phoneNumber(string): Customer phone number (primary key)creditCustomersCount(number): Number of credit customerstotalCreditBaseline(number): Baseline credit amountcreditCustomerTypes(string): Types of credit customerscreditTypicalDays(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 performedmicroActionScript(string): Script or details of 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 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 would need to be handled by the calling workflow.
Known Limitations¶
- No validation of input parameters before database insertion
- No error handling for database connection issues
- Assumes phone number is always provided and valid
- Weekly recovery calculations reset logic is not clearly defined
Related Workflows¶
No related workflows are documented in the provided context.
Setup Instructions¶
-
Import the Workflow
- Copy the workflow JSON and import it into your n8n instance
-
Configure Database Credential
- Create a PostgreSQL credential named
PostgresOnSupabase - Configure connection to your Supabase PostgreSQL instance
- Ensure the credential has read/write access to the
creditTrackingtable
- Create a PostgreSQL credential named
-
Database Schema Requirements
- Ensure your PostgreSQL database has a
creditTrackingtable with all the required columns - The table should have
phoneNumberas the primary key for conflict resolution - Required columns include all input parameters plus calculated fields like
totalCreditLockedandweeklyRecoveredSoFar
- Ensure your PostgreSQL database has a
-
Test the Workflow
- Execute the workflow with sample data to verify database connectivity
- Confirm that upsert logic works correctly for both new and existing records
-
Integration
- Call this workflow from other workflows using the Execute Workflow node
- Pass all required parameters as defined in the trigger configuration