Best answer

What are best practices for separating first and last name using Formatter: Split Text?

  • 27 January 2023
  • 3 replies
  • 244 views

I’m setting up formatter: split text to separate a full name field into a first and last name field. I am using the Segment Index: All (as Separate Fields). This is my setup:

First Name: Item 1
Last Name: Item 2

I think it will work great when people just enter a first and last name:

First Name: Stephen
Last Name: Strange

My fear is that people will occasionally enter titles and additional names. Would Dr. Stephen Vincent Strange become:

First Name: Dr.
Last Name: Stephen

Would I lose all of the extra data? What is the best practice here? Without some sort of name-parsing AI - I think the best outcome would be letting the extra fields get added to the last name field somehow. What would that look like?

or is there an option to pass text with more than 2 segments in a different way? I could have these flagged for manual review into our CRM. 

And if any of this is possible will it require a lot of extra tasks? The way I have it set up - it should just be one task.

Any best practices or tips / tricks would be appreciated!

icon

Best answer by Troy Tessalone 27 January 2023, 05:56

View original

This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

3 replies

Userlevel 7
Badge +14

Hi @Hugaluga 

Good question.

Check out this topic:

 

@Troy Tessalone thank you! The thread you linked was super helpful.

I’m not super confident in my JavaScript, but I think this modified version of your code should split 2 part names and pass longer names to us in a separate field for manual entry (our CRM will alert us).

const WordCount = inputData.NameFull.trim().split(' ').length; // counts full name words

if (WordCount > 2) {
let NameError = "Manual entry required: " + inputData.NameFull; // adds manual entry note to full name
output = [{NameError}];
} else {
let NameFull = inputData.NameFull.trim().split(' '); // removes whitespace and splits by spaces
let NameFirst = NameFull[0]; // takes first array item
let NameLast = NameFull[NameFull.length - 1]; // takes last array item
output = [{NameFirst, NameLast}];
}

If you see anything wrong, please let me know; Otherwise, I hope this helps someone else!

If someone wants a version that doesn’t throw status errors:

const WordCount = inputData.NameFull.trim().split(' ').length; // counts full name words

if (WordCount > 2) {
let NameFirst = null; // creates blank entry for first name
let NameLast = null; // creates blank entry for last name
let NameError = "Manual entry required: " + inputData.NameFull; // adds manual entry note to full name
output = [{NameFirst, NameLast, NameError}];
} else {
let NameFull = inputData.NameFull.trim().split(' '); // removes whitespace and splits by spaces
let NameFirst = NameFull[0]; // takes first array item
let NameLast = NameFull[NameFull.length - 1]; // takes last array item
let NameError = null; // creates blank entry for name error
output = [{NameFirst, NameLast, NameError}];
}

I believe it is functionally the same… but Zapier won’t display errors and filling out the next step of the zap might be easier.