Using Zapier, here’s a problem you’ll run into a lot: The trigger app provides a person’s full name, and the action app asks for first name and last name separately.
Below you’ll learn the best & easiest way to split a full name into first, last and middle names.
Note that multi-step Zaps require a paid account. Every way to spilt names currently requires a middle step, so unfortunately this is unavoidable.
Most solutions for this use Zapier Formatter. While this is a simple setup, it requires 2 steps in your Zap, which uses up more tasks. They also usually only show how to get the first and last names, leaving everything in the middle out.
This solution uses only 1 step and also splits out the middle name.
The example below shows a Trigger from Content Snare that has returned a full name.
Next:
- Add a step using the + icon after the trigger
- Choose the app “Code by Zapier”
- Run the Action Event “Run Javascript”
Click continue and set up the action like this:
- In the left “input data” box, type “name”
- In the right box, add the name from the trigger
- In the code box, paste in the code below
var names = input.name.split(' ');
if (names.length > 2) {
output = [{firstname: names[0], middlenames: names.slice(1, -1).join(' ') , lastname: names[names.length - 1]}];
}
else if (names.length < 2) {
output = [{firstname: names[0], middlenames: '', lastname: ''}];
}
else {
output = [{firstname: names[0], middlenames: '', lastname: names[names.length - 1]}];
}
Then hit continue, then ‘test & review’.
Now, when you create your next action, you should get Firstname, Lastname and Middlenames as options to send.
This all!
If you’d like to learn more Zapier tips, sign up below.