Skip to content

Save Onboarding Baseline Tool

This workflow saves baseline business information for youth entrepreneurs during their onboarding process. It accepts key business metrics like monthly costs, operating days, and stock type, then stores this data in a PostgreSQL database for later use in coaching and analysis.

Purpose

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

How It Works

  1. Receive Input: The workflow accepts baseline business data including phone number, preferred contact time, monthly fixed costs, business days per month, daily fixed cost, and stock type
  2. Clean Data: A JavaScript code node sanitizes the input by removing empty or null values while preserving the phone number as the primary identifier
  3. Update Database: The cleaned data is used to update the youth entrepreneur's record in the PostgreSQL database using an upsert operation
  4. Format Response: The workflow returns a success indicator and confirmation message based on whether the database operation completed successfully

Workflow Diagram

graph TD
    A[Trigger] --> B[Code in JavaScript]
    B --> C[updateBaseline]
    C --> D[formatResponse]

    E[upsertBaseline] 
    F[upsertBaseline1]
    G[formatResponse1]

    style A fill:#e1f5fe
    style D fill:#e8f5e8

Trigger

Execute Workflow Trigger: This workflow is designed to be called by other workflows or external systems. It accepts the following input parameters: - phoneNumber (required) - The youth entrepreneur's phone number as unique identifier - preferredTime - Preferred time for contact - monthlyFixedCosts - Monthly fixed business costs - businessDaysMonth - Number of business days per month - dailyFixedCost - Daily fixed cost calculation - stockType - Type of stock/inventory the business handles

Nodes Used

Node Type Node Name Purpose
Execute Workflow Trigger Trigger Receives input parameters from calling workflows
Code Code in JavaScript Sanitizes input data by removing empty values
Postgres updateBaseline Updates the youth entrepreneur record in the database
Set formatResponse Formats the final response with success status and message
Postgres upsertBaseline (Unused) Alternative database operation node
Postgres upsertBaseline1 (Unused) Alternative database operation node
Set formatResponse1 (Unused) Alternative response formatting node

External Services & Credentials Required

  • PostgreSQL Database: Requires connection to the kdpTables database
    • Credential name: kdpTables
    • Database table: youthEntrepreneursReal
    • Required permissions: INSERT, UPDATE, SELECT

Environment Variables

No environment variables are explicitly used in this workflow. Database connection details are managed through n8n's credential system.

Data Flow

Input:

1
2
3
4
5
6
7
8
{
  "phoneNumber": "+254116377439",
  "preferredTime": "morning",
  "monthlyFixedCosts": "200",
  "businessDaysMonth": "30",
  "dailyFixedCost": "7",
  "stockType": "perishable"
}

Output:

1
2
3
4
{
  "success": true,
  "message": "Baseline saved."
}

The workflow performs an upsert operation, meaning it will either insert a new record or update an existing one based on the phone number. Only non-empty values are included in the database operation.

Error Handling

The database nodes are configured with onError: "continueRegularOutput", which means the workflow will continue executing even if database operations fail. The response formatting logic checks for the presence of a returned phone number to determine success:

  • If phoneNumber is returned from the database operation: success: true
  • If no phone number is returned: success: false with message "No rows returned — check upsert."

Known Limitations

No specific limitations documented in the provided context.

No related workflows specified in the provided context.

Setup Instructions

  1. Import the Workflow: Import the JSON workflow file into your n8n instance

  2. Configure Database Credentials:

    • Create a PostgreSQL credential named kdpTables
    • Configure connection to your database containing the youthEntrepreneursReal table
  3. Database Table Requirements: Ensure your PostgreSQL database has a table named youthEntrepreneursReal with the following columns:

    • phoneNumber (TEXT, primary key)
    • preferredTime (TEXT)
    • monthlyFixedCosts (NUMERIC)
    • businessDaysPerMonth (INTEGER)
    • dailyFixedCost (NUMERIC)
    • stockType (TEXT)
  4. Test the Workflow: Use the provided test data to verify the workflow functions correctly:

    1
    2
    3
    4
    5
    6
    7
    8
    {
      "phoneNumber": "+254116377439",
      "preferredTime": null,
      "monthlyFixedCosts": "200",
      "businessDaysMonth": "30",
      "dailyFixedCost": "7",
      "stockType": null
    }
    

  5. Integration: This workflow is designed to be called by other workflows using the "Execute Workflow" node, passing the required baseline data as parameters.