V4 - updateUserStatusTool¶
A utility workflow that updates the onboarding status of youth entrepreneurs in the database and maintains an audit log of all status changes.
Purpose¶
No business context provided yet — add a context.md to enrich this documentation.
This workflow serves as a centralized tool for updating user onboarding statuses in the youth entrepreneurs database. It validates that users exist before making updates and maintains a complete audit trail of status changes for compliance and tracking purposes.
How It Works¶
- Receives Input: The workflow accepts a phone number and new onboarding status from another workflow
- Validates User Exists: Checks if exactly one user exists with the provided phone number
- Handles Invalid Users: If the user doesn't exist or multiple records are found, returns an error message
- Logs Status Change: For valid users, records the previous and new status in an audit log
- Updates Status: Updates the user's onboarding status in the main database
- Confirms Success: Returns a confirmation message with the updated phone number
Workflow Diagram¶
graph TD
A[When Executed by Another Workflow] --> B[Execute a SQL query]
B --> C[If]
C -->|User Found| D[Execute a SQL query1]
C -->|User Not Found| E[Edit Fields - Error]
D --> F[Log Status Change]
D --> G[Insert or update rows in a table]
G --> H[Edit Fields1 - Success]
Trigger¶
Execute Workflow Trigger: This workflow is designed to be called by other workflows, not triggered directly. It expects two input parameters:
- phoneNumber: The phone number of the user to update
- onboardingStatus: The new status to set for the user
Nodes Used¶
| Node Type | Node Name | Purpose |
|---|---|---|
| Execute Workflow Trigger | When Executed by Another Workflow | Receives input parameters from calling workflow |
| Postgres | Execute a SQL query | Counts users with the provided phone number |
| If | If | Validates that exactly one user exists |
| Set | Edit Fields | Returns error message for invalid users |
| Postgres | Execute a SQL query1 | Retrieves the user ID for the phone number |
| Postgres | Log Status Change | Records status change in audit log |
| Postgres | Insert or update rows in a table | Updates the user's onboarding status |
| Set | Edit Fields1 | Returns success confirmation message |
External Services & Credentials Required¶
- PostgreSQL Database: Requires connection credentials for the database containing:
youthEntrepreneursRealtable (main user data)userStatusLogtable (audit trail)
Environment Variables¶
No specific environment variables are required beyond the standard n8n database connection configuration.
Data Flow¶
Input:
1 2 3 4 | |
Output (Success):
1 2 3 | |
Output (Error):
1 2 3 | |
Error Handling¶
The workflow includes built-in error handling:
- User Validation: If the phone number doesn't match exactly one user record, the workflow returns an error message instead of attempting to update
- Error Workflow: The workflow is configured to use error workflow
cuHEGQjAfvuGwIODfor handling unexpected failures - Graceful Failure: Invalid requests result in a controlled error response rather than workflow failure
Known Limitations¶
- The workflow only accepts phone numbers as user identifiers
- Updates are limited to the
onboardingStatusfield only - No validation is performed on the new status value
- The workflow assumes the calling workflow has already validated the input parameters
Related Workflows¶
This workflow is designed to be called by other workflows in the system. Check for workflows that reference this workflow ID (7vM1qop37b5jNHCk) in their Execute Workflow nodes.
Setup Instructions¶
- Import the Workflow: Import the JSON into your n8n instance
- Configure Database Connection: Set up PostgreSQL credentials with access to:
youthEntrepreneursRealtableuserStatusLogtable
- Verify Table Schema: Ensure the following columns exist:
youthEntrepreneursReal:id,phoneNumber,onboardingStatususerStatusLog:phoneNumber,previousStatus,newStatus
- Set Error Workflow: Configure error workflow
cuHEGQjAfvuGwIODor update the reference - Test the Workflow: Execute with sample data to verify database connectivity
- Configure Calling Workflows: Update other workflows to call this workflow with the required parameters
The workflow is currently inactive and should be activated once configuration is complete.