Skip to content

V4 - saveOnboardingBaselineTool

A workflow tool that saves or updates baseline business information for youth entrepreneurs during their onboarding process. This workflow handles the storage of essential business metrics like fixed costs, operating days, stock types, and practice baseline averages in the youth entrepreneurs database.

Purpose

No business context provided yet — add a context.md to enrich this documentation.

This workflow appears to be part of a youth entrepreneurship program system, designed to capture and store baseline business information during participant onboarding. It allows for flexible updates of business metrics while maintaining data integrity through upsert operations.

How It Works

  1. Receives Input: The workflow accepts baseline business data including phone number, preferred contact time, monthly fixed costs, business days per month, daily fixed costs, stock type, and practice baseline averages
  2. Builds Dynamic Query: A JavaScript code node analyzes the input data and constructs an appropriate SQL UPDATE query, only including fields that have valid values
  3. Validates Query: The workflow checks if there's actually a query to execute (i.e., if any valid data was provided)
  4. Executes Database Update: If valid data exists, it runs the SQL query against the PostgreSQL database to update the youth entrepreneur's baseline information
  5. Returns Response: The workflow formats and returns a success/failure response with appropriate messaging

Workflow Diagram

graph TD
    A[Trigger] --> B[Code in JavaScript]
    B --> C[hasQuery]
    C -->|Has Query| D[executeBaselineSQL]
    C -->|No Query| E[formatResponse]
    D --> E

Trigger

Execute Workflow Trigger - This workflow is designed to be called by other workflows or external systems. It expects the following input parameters:

  • phoneNumber (string) - Unique identifier for the youth entrepreneur
  • preferredTime (string) - Preferred contact time
  • monthlyFixedCosts (number) - Monthly fixed business expenses
  • businessDaysMonth (number) - Number of business days per month
  • dailyFixedCost (number) - Daily fixed cost calculation
  • stockType (string) - Type of stock/inventory managed
  • practiceBaselineAvg (number) - Practice baseline average metric

Nodes Used

Node Type Node Name Purpose
Execute Workflow Trigger Trigger Receives input parameters from calling workflows
Code (JavaScript) Code in JavaScript Builds dynamic SQL UPDATE query based on provided data
If hasQuery Checks if there's a valid query to execute
Postgres executeBaselineSQL Executes the SQL query against the database
Set formatResponse Formats the final response with success status and message

External Services & Credentials Required

  • PostgreSQL Database: Requires connection to a PostgreSQL database containing the youthEntrepreneursReal table
    • Database credentials needed for the Postgres nodes
    • Table must have columns: phoneNumber, preferredTime, monthlyFixedCosts, businessDaysPerMonth, dailyFixedCost, stockType, practiceBaselineAvg

Environment Variables

No specific environment variables are referenced in this workflow. Database connection details are handled through n8n's credential system.

Data Flow

Input:

1
2
3
4
5
6
7
8
9
{
  "phoneNumber": "string (required)",
  "preferredTime": "string (optional)",
  "monthlyFixedCosts": "number (optional)",
  "businessDaysMonth": "number (optional)", 
  "dailyFixedCost": "number (optional)",
  "stockType": "string (optional)",
  "practiceBaselineAvg": "number (optional)"
}

Output:

1
2
3
4
{
  "success": "boolean",
  "message": "string"
}

Error Handling

  • The executeBaselineSQL node has error handling configured to continue on error rather than fail the workflow
  • The JavaScript code node validates input data and handles cases where no valid fields are provided for update
  • The conditional logic ensures SQL queries are only executed when there's actual data to update

Known Limitations

  • The workflow contains duplicate/unused nodes (upsertBaseline, upsertBaseline1, updateBaseline, formatResponse1) that appear to be from previous iterations
  • Phone number is required as the primary key for updates - workflow will not function without it
  • The workflow only updates existing records; it doesn't create new youth entrepreneur entries
  • String values are escaped for SQL injection protection, but numeric validation relies on JavaScript's Number() function

This workflow references an error workflow with ID cuHEGQjAfvuGwIOD for error handling, though no other specific related workflows are mentioned in the configuration.

Setup Instructions

  1. Import the Workflow: Import the JSON into your n8n instance
  2. Configure Database Connection:
    • Set up PostgreSQL credentials in n8n
    • Ensure connection to database with youthEntrepreneursReal table
  3. Verify Table Schema: Confirm the target table has all required columns with appropriate data types
  4. Test the Workflow:
    • Call the workflow with sample data to verify database connectivity
    • Test with various combinations of optional fields to ensure proper handling
  5. Clean Up: Consider removing the unused nodes (upsertBaseline, upsertBaseline1, etc.) to simplify the workflow
  6. Set Permissions: Configure the workflow's caller policy as needed (currently set to "workflowsFromSameOwner")