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.
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
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
Step 2: Custom code action
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
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?
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
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
Step 2: Custom code action
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
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?
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.
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!
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
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