Skip to content

V4 - updateUserDataTool

A utility workflow that updates user profile information in the youth entrepreneurs database. This workflow validates user existence by phone number and updates their first name, second name, and business ownership status.

Purpose

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

How It Works

  1. Receives Input: The workflow accepts four parameters: phone number, first name, second name, and business ownership status
  2. Validates User Exists: Queries the database to check if exactly one user exists with the provided phone number
  3. Conditional Processing:
    • If user exists: Retrieves their ID and updates their profile information
    • If user doesn't exist or multiple records found: Returns an error message
  4. Updates Database: Uses an upsert operation to update the user's first name, second name, and business ownership information
  5. Returns Result: Provides a success message with the phone number or an error message

Workflow Diagram

graph TD
    A[When Executed by Another Workflow] --> B[Execute a SQL query]
    B --> C[If]
    C -->|User exists| D[Execute a SQL query1]
    C -->|User not found| E[Edit Fields - Error]
    D --> F[Insert or update rows in a table]
    F --> G[Edit Fields1 - Success]

Trigger

Execute Workflow Trigger: This workflow is designed to be called by other workflows, not triggered directly. It accepts the following input parameters: - phoneNumber - The user's phone number (used as identifier) - firstName - New first name to update - secondName - New second name to update
- businessOwned - Business ownership status to update

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 Checks if exactly one user exists with the phone number
Postgres Execute a SQL query1 Retrieves the user ID for the phone number
Postgres Insert or update rows in a table Updates user profile information
Set Edit Fields Returns error message when user validation fails
Set Edit Fields1 Returns success message after successful update

External Services & Credentials Required

  • PostgreSQL Database: Requires connection to a Postgres database containing the youthEntrepreneursReal table
  • Database Credentials: PostgreSQL connection credentials with read/write access to the user table

Environment Variables

No specific environment variables are required. Database connection details are managed through n8n's credential system.

Data Flow

Input:

1
2
3
4
5
6
{
  "phoneNumber": "string",
  "firstName": "string", 
  "secondName": "string",
  "businessOwned": "string"
}

Output (Success):

1
2
3
{
  "output": "User record for phone number [phoneNumber] has been updated"
}

Output (Error):

1
2
3
{
  "output": "Error updating user data"
}

Error Handling

The workflow includes basic 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 with an error workflow (ID: cuHEGQjAfvuGwIOD) to handle unexpected failures
  • Caller Policy: Restricted to workflows from the same owner for security

Known Limitations

  • Only updates three specific fields: firstName, secondName, and businessOwned
  • Requires exact phone number match - no fuzzy matching or phone number normalization
  • No validation of input data format or content
  • Error messages are generic and don't specify the exact issue (e.g., user not found vs. multiple users found)

No related workflows identified from the provided context.

Setup Instructions

  1. Import 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: Ensure the target table has these columns:
    • id (number, primary key)
    • phoneNumber (string)
    • firstName (string)
    • secondName (string)
    • businessOwned (string)
  4. Test Execution: Call the workflow from another workflow with test data to verify functionality
  5. Configure Error Handling: Ensure the referenced error workflow exists or update the error workflow ID

Database Table Requirements: The youthEntrepreneursReal table must exist with appropriate columns and the calling workflow must have the necessary permissions to read and update records.