Save Onboarding Baseline Tool¶
This workflow provides a utility service for saving and updating baseline business information collected during the onboarding process. It accepts key business metrics like monthly costs, operating days, and stock types, then intelligently updates the youth entrepreneur database while preserving existing data.
Purpose¶
No business context provided yet — add a context.md to enrich this documentation.
How It Works¶
-
Input Processing: The workflow receives 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.
-
Query Generation: A JavaScript code node analyzes the input data and builds a dynamic SQL UPDATE query, only including fields that have actual values (skipping null, undefined, or empty values).
-
Conditional Execution: The workflow checks if there are any fields to update. If no valid data is provided, it skips the database operation.
-
Database Update: When valid data exists, it executes the generated SQL query to update the youth entrepreneur record, matching by phone number.
-
Response Formatting: Finally, it formats a standardized response indicating success or failure with an appropriate message.
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 as a sub-workflow. It accepts the following input parameters:
- phoneNumber (required)
- preferredTime
- monthlyFixedCosts
- businessDaysMonth
- dailyFixedCost
- stockType
- practiceBaselineAvg
Nodes Used¶
| Node Type | Node Name | Purpose |
|---|---|---|
| Execute Workflow Trigger | Trigger | Receives input parameters from calling workflow |
| Code (JavaScript) | Code in JavaScript | Builds dynamic SQL UPDATE query based on provided data |
| IF | hasQuery | Checks if there are fields to update |
| Postgres | executeBaselineSQL | Executes the generated SQL query |
| Set | formatResponse | Creates standardized success/failure response |
External Services & Credentials Required¶
- PostgreSQL Database: Requires connection to the
youthEntrepreneursRealtable- Credential ID:
EJPqF6MDH1ZwAzyv(named "Postgres account") - Permissions needed: UPDATE access on
youthEntrepreneursRealtable
- Credential ID:
Environment Variables¶
No environment variables are used in this workflow. Database connection details are managed through n8n credentials.
Data Flow¶
Input¶
1 2 3 4 5 6 7 8 9 | |
Output¶
1 2 3 4 | |
Database Fields Updated¶
The workflow updates the following columns in the youthEntrepreneursReal table:
- preferredTime
- monthlyFixedCosts
- businessDaysPerMonth (mapped from input businessDaysMonth)
- dailyFixedCost
- stockType
- practiceBaselineAvg
Error Handling¶
- Database Errors: The
executeBaselineSQLnode is configured with "Continue on Error" to prevent workflow failure - Missing Phone Number: The JavaScript code validates that a phone number is provided before generating queries
- Empty Data: If no valid fields are provided for update, the workflow returns a success message indicating no update was needed
- SQL Injection Protection: Phone numbers are properly escaped in the generated SQL queries
Known Limitations¶
- The workflow only updates existing records; it does not create new youth entrepreneur entries
- Phone number is used as the primary identifier and must already exist in the database
- Zero values are treated as valid data (e.g.,
monthlyFixedCosts: 0will update the field) - The workflow assumes the
youthEntrepreneursRealtable structure matches the expected column names
Related Workflows¶
This is a utility workflow designed to be called by other workflows in the system. Check for workflows that handle onboarding processes or baseline data collection that might invoke this tool.
Setup Instructions¶
-
Import the Workflow: Import the JSON into your n8n instance
-
Configure Database Credentials:
- Create a PostgreSQL credential named "Postgres account"
- Ensure it has UPDATE permissions on the
youthEntrepreneursRealtable - Update the credential ID if different from
EJPqF6MDH1ZwAzyv
-
Verify Database Schema: Ensure your
youthEntrepreneursRealtable has these columns:phoneNumber(TEXT, used for matching)preferredTime(TEXT)monthlyFixedCosts(NUMERIC)businessDaysPerMonth(INTEGER)dailyFixedCost(NUMERIC)stockType(TEXT)practiceBaselineAvg(NUMERIC)
-
Test the Workflow:
- Use the "Execute Workflow" feature with sample data
- Verify database updates are working correctly
- Check error handling with invalid inputs
-
Integration: Call this workflow from other workflows using the "Execute Workflow" node with the required input parameters