CMS Development

DDavis37
Participant

HELP NEEDED - Seperate first and last name automatically via a workflow

SOLVE

Hello
I would like to know how to set up a workflow that will rename a contact automatically from an email address by separating the first and last name when the email address contains a dot. 

For example - the email address is danika.davis@flf.nz, i want Hubspot to rename the record to Danika Davis automatically. 

I am not a coder so I am looking for some help here as I'm sure this could be done via some custom code. 

Thanks 

0 Upvotes
1 Accepted solution
Jaycee_Lewis
Solution
Community Manager
Community Manager

HELP NEEDED - Seperate first and last name automatically via a workflow

SOLVE

Hey, @DDavis37 👋 Do you have access to Custom Coded Workflow actions (Operations Hub Professional required)?

 

I have something I just built based on your request that might be helpful (or other folks who find this post in the future). It's likely not production ready, but should be a good leaping off point. 

 

First, let's look at the limitations we have to deal with:

  • HubSpot workflows don't have a “matches regex” filter option
  • “Contains dot” filter alone catches domain extensions (.com, .org, etc.)
  • No built-in “Split text” action in workflows
  • Can't directly validate the position of the dot in email (before/after @) in standard workflow actions
  • Workflow will still enroll contacts that don't match our exact needs (dot before @), so the code needs to handle the validation
  • No native way to preview what the split names will be before running the workflow
  • We're assuming that the first/last name formatting is consistent
    Won't handle:
    — Middle names (mary.jane.smith@…)
    - Hyphenated names (jean-paul.smith@…)
    - Multiple word surnames (van.der.berg@…)
    - Special characters or accents in names (josé.garcia@…)

         - Other variations I haven't thought of 😊

 

Step 1: Workflow enrollment options

  • Email is known
  • Email contains any of . (that's a period 😊)
  • First name is unknown

CleanShot 2024-12-12 at 15.47.12@2x.png

Step 2: Custom code action

CleanShot 2024-12-12 at 15.35.52@2x.png

exports.main = async (event, callback) => {
    const email = event.inputFields['email'];
    
    // Split at @ and check first part for proper format
    const parts = email.split('@');
    if (!parts[0] || !parts[0].includes('.')) {
        callback({
            outputFields: {
                firstName: '',
                lastName: ''
            }
        });
        return;
    }

    // Process only if dot is in the name part (before @)
    const namePart = parts[0];
    const nameArray = namePart.split('.');
    
    // Check if we have both first and last name
    if (nameArray.length !== 2) {
        callback({
            outputFields: {
                firstName: '',
                lastName: ''
            }
        });
        return;
    }

    const [firstName, lastName] = nameArray;
    
    callback({
        outputFields: {
            firstName: firstName.charAt(0).toUpperCase() + firstName.slice(1),
            lastName: lastName.charAt(0).toUpperCase() + lastName.slice(1)
        }
    });
}

 

Step 3: Copy the outputs to your First and Last Name properties

CleanShot 2024-12-12 at 15.37.48@2x.png

 

I'd recommend using a Developer Test Account via an App Developer account to set up this workflow and test on test contacts before unleashing this live in a production account. FYI, You don't need to build an app to use a Developer Test Account. 

 

If you have other naming conventions aside from “firstName.lastName@SOMEDOMAIN.com”, the code would need to be adjusted to handle those variations. 

 

The main issue someone smarter than me will need to solve — how to fix the enrollment condition to not enroll all your records who have an email address (the custom code action handles the parsing in this case) Hey @eburnaman @GiantFocal @danmoyle @Kevin-C @MatthiasKunz do you have any thoughts on alternative ways to handle the enrollment? 

 

Have fun building! — Jaycee

linkedin

Jaycee Lewis

Developer Community Manager

Community | HubSpot

View solution in original post

8 Replies 8
Jaycee_Lewis
Solution
Community Manager
Community Manager

HELP NEEDED - Seperate first and last name automatically via a workflow

SOLVE

Hey, @DDavis37 👋 Do you have access to Custom Coded Workflow actions (Operations Hub Professional required)?

 

I have something I just built based on your request that might be helpful (or other folks who find this post in the future). It's likely not production ready, but should be a good leaping off point. 

 

First, let's look at the limitations we have to deal with:

  • HubSpot workflows don't have a “matches regex” filter option
  • “Contains dot” filter alone catches domain extensions (.com, .org, etc.)
  • No built-in “Split text” action in workflows
  • Can't directly validate the position of the dot in email (before/after @) in standard workflow actions
  • Workflow will still enroll contacts that don't match our exact needs (dot before @), so the code needs to handle the validation
  • No native way to preview what the split names will be before running the workflow
  • We're assuming that the first/last name formatting is consistent
    Won't handle:
    — Middle names (mary.jane.smith@…)
    - Hyphenated names (jean-paul.smith@…)
    - Multiple word surnames (van.der.berg@…)
    - Special characters or accents in names (josé.garcia@…)

         - Other variations I haven't thought of 😊

 

Step 1: Workflow enrollment options

  • Email is known
  • Email contains any of . (that's a period 😊)
  • First name is unknown

CleanShot 2024-12-12 at 15.47.12@2x.png

Step 2: Custom code action

CleanShot 2024-12-12 at 15.35.52@2x.png

exports.main = async (event, callback) => {
    const email = event.inputFields['email'];
    
    // Split at @ and check first part for proper format
    const parts = email.split('@');
    if (!parts[0] || !parts[0].includes('.')) {
        callback({
            outputFields: {
                firstName: '',
                lastName: ''
            }
        });
        return;
    }

    // Process only if dot is in the name part (before @)
    const namePart = parts[0];
    const nameArray = namePart.split('.');
    
    // Check if we have both first and last name
    if (nameArray.length !== 2) {
        callback({
            outputFields: {
                firstName: '',
                lastName: ''
            }
        });
        return;
    }

    const [firstName, lastName] = nameArray;
    
    callback({
        outputFields: {
            firstName: firstName.charAt(0).toUpperCase() + firstName.slice(1),
            lastName: lastName.charAt(0).toUpperCase() + lastName.slice(1)
        }
    });
}

 

Step 3: Copy the outputs to your First and Last Name properties

CleanShot 2024-12-12 at 15.37.48@2x.png

 

I'd recommend using a Developer Test Account via an App Developer account to set up this workflow and test on test contacts before unleashing this live in a production account. FYI, You don't need to build an app to use a Developer Test Account. 

 

If you have other naming conventions aside from “firstName.lastName@SOMEDOMAIN.com”, the code would need to be adjusted to handle those variations. 

 

The main issue someone smarter than me will need to solve — how to fix the enrollment condition to not enroll all your records who have an email address (the custom code action handles the parsing in this case) Hey @eburnaman @GiantFocal @danmoyle @Kevin-C @MatthiasKunz do you have any thoughts on alternative ways to handle the enrollment? 

 

Have fun building! — Jaycee

linkedin

Jaycee Lewis

Developer Community Manager

Community | HubSpot

danmoyle
Most Valuable Member | Elite Partner
Most Valuable Member | Elite Partner

HELP NEEDED - Seperate first and last name automatically via a workflow

SOLVE

Thanks for the compliment @Jaycee_Lewis but I have no notes on your custom workflow you shared with @DDavis37. This one's beyond my experience 😊 

 

Did my answer help? Please "mark as a solution" to help others find answers. Plus I really appreciate it!


Dan Moyle

HubSpot Advisor

LearningOps | Impulse Creative

emailAddress
dan@impulsecreative.com
website
https://impulsecreative.com/
Jaycee_Lewis
Community Manager
Community Manager

HELP NEEDED - Seperate first and last name automatically via a workflow

SOLVE

I made a small mistake at the end. It won't enroll all your Contacts with an email and a “.” somewhere in there. But it will enroll all that are missing a “first name” and meet the other conditions.

 

One way to test how many would enroll (but not how many would be updated once the code action runs) would be to just set up the enrollment condition and use the “Review and Publish” option to generate a list of the matching Contacts who would enroll. 

 

Best,

Jaycee

linkedin

Jaycee Lewis

Developer Community Manager

Community | HubSpot

0 Upvotes
Jaycee_Lewis
Community Manager
Community Manager

HELP NEEDED - Seperate first and last name automatically via a workflow

SOLVE

I forgot to include the result of my test.

CleanShot 2024-12-12 at 16.00.10@2x.png

CleanShot 2024-12-12 at 15.59.54@2x.png

😊 — Jaycee

linkedin

Jaycee Lewis

Developer Community Manager

Community | HubSpot

0 Upvotes
ArisudanTiwari
Participant

HELP NEEDED - Seperate first and last name automatically via a workflow

SOLVE

Hi @DDavis37 ,

HubSpot workflows don’t have a built-in feature to extract names directly from email addresses. However, you can explore integrating HubSpot with services like Parse.ly or Clearbit, which specialize in extracting contact information from email addresses.

Let me know if you’d like further guidance on this!

0 Upvotes
DDavis37
Participant

HELP NEEDED - Seperate first and last name automatically via a workflow

SOLVE

Thanks @ArisudanTiwari 
Zapier seems to be the favourite service to intergrate with but I'm having a little difficulty actually creating the zap. 
Wanting any contact in our system that has an email address for the first name to be split into first and last name if they have a . in their email address

0 Upvotes
GiantFocal
Top Contributor | Partner
Top Contributor | Partner

HELP NEEDED - Seperate first and last name automatically via a workflow

SOLVE

Hi @DDavis37,

 

I doubt this is doable with just HubSpot workflows, but AI could easily handle it. 

Connect via Zapier, Make, or another API integrator to automate tasks with AI of your choice.

 

An example of the prompt might be:

 

 

Fetch first and last names from email. For example: Danika Davis from danika.davis@flf.nz
Now fetch for: %email%

 

Best regards,
Ernesto @ GiantFocal
Found this answer helpful?
Marking it as the solution helps both the community and me - thanks in advance!
0 Upvotes
DDavis37
Participant

HELP NEEDED - Seperate first and last name automatically via a workflow

SOLVE

Thanks for that, i have a look at Zapier and it does seem to have the features for this but I'm unsure of the exact steps to take to get it outputting the email addresses as that prompt you gave me is asking for me to provide the email addresses to get the outputs, but i obviously cannot type in every single email address in our system 

0 Upvotes