# Custom code / Format Data - split full name property

**URL:** <https://community.hubspot.com/t/custom-code-format-data-split-full-name-property/72665>\
**Category:** Data Hub\
**Tags:** workflow-extension, format-data-actions\
**Created:** [January 11, 2023, 2:05pm UTC](https://community.hubspot.com/t/custom-code-format-data-split-full-name-property/72665 "2023-01-11T14:05:03Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![ShlomiGani](https://avatars.discourse-cdn.com/v4/letter/s/7ab992/32.png) [@ShlomiGani](https://community.hubspot.com/u/ShlomiGani)\
**Post date:** [January 11, 2023, 2:05pm UTC](https://community.hubspot.com/t/custom-code-format-data-split-full-name-property/72665/1 "2023-01-11T14:05:03Z")

</div>

Hi everyone,

Unfortunately I didn’t find any split command in the format data option.

We do pay for OPS enterprise and I would like to keep this action in house instead of exporting it to [Make.com](http://Make.com) / Zapier.

Has anyone ever tried to create custom code for this split and can share it with me? (I usually work with no code / low code platforms)

---

<div class="post-metadata">

**Author:** ![ChrisoKlepke](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/chrisoklepke/32/11213_2.png) [@ChrisoKlepke](https://community.hubspot.com/u/ChrisoKlepke)\
**Post date:** [January 11, 2023, 2:50pm UTC](https://community.hubspot.com/t/custom-code-format-data-split-full-name-property/72665/2 "2023-01-11T14:50:21Z")

</div>

Hey @ShlomiGani ,

what is it that you need to split and what results do you need. For example, in this short Python code for a custom code action, we use an input field (assuming it is a string) and split it at spaces. The result then would be a list. So if the input string is:

`"Never gonna give you up Never gonna let you down"`

The result would be:

`['Never', 'gonna', 'give', 'you', 'up', 'Never', 'gonna', 'let', 'you', 'down']`

Here is the code:

```lia-code-sample
def main(event):

 input_string = event.get("inputFields").get("input_string")

 output_list = input_string.split(" ")

 return {"outputFields": {"output": output_list}}

```

But I assume there might be more to it depending on what your input data is and what output you expect.

Cheers,

Chriso

---

<div class="post-metadata">

**Author:** ![ChrisoKlepke](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/chrisoklepke/32/11213_2.png) [@ChrisoKlepke](https://community.hubspot.com/u/ChrisoKlepke)\
**Post date:** [January 11, 2023, 2:56pm UTC](https://community.hubspot.com/t/custom-code-format-data-split-full-name-property/72665/3 "2023-01-11T14:56:50Z")

</div>

Just noticing the title of the thread 😅 Here it is for full name getting first and last name.

```lia-code-sample
def main(event):

 full_name = event.get("inputFields").get("input_string")

 name_list = full_name.split(" ")

 first_name = name_list[0]

 last_name = name_list[-1]

 return {
 "outputFields": {
 "first_name": first_name,
 "last_name": last_name,
 }
 }

```

---

<div class="post-metadata">

**Author:** ![ShlomiGani](https://avatars.discourse-cdn.com/v4/letter/s/7ab992/32.png) [@ShlomiGani](https://community.hubspot.com/u/ShlomiGani)\
**Post date:** [January 11, 2023, 3:50pm UTC](https://community.hubspot.com/t/custom-code-format-data-split-full-name-property/72665/4 "2023-01-11T15:50:01Z")

</div>

Hi Chrisotoph, Tnx for your quick answers.

Should I replace the green quets with the property lables?

As it is I get an eror .

```auto
[ERROR] AttributeError: 'NoneType' object has no attribute 'get'
Traceback (most recent call last)

```

---

<div class="post-metadata">

**Author:** ![ChrisoKlepke](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/chrisoklepke/32/11213_2.png) [@ChrisoKlepke](https://community.hubspot.com/u/ChrisoKlepke)\
**Post date:** [January 12, 2023, 8:25am UTC](https://community.hubspot.com/t/custom-code-format-data-split-full-name-property/72665/5 "2023-01-12T08:25:16Z")

</div>

Hey @ShlomiGani ,

sure, let me show you how to set up the custom code action with some screenshots.

The most important stuff is the following:

- Language: Python 3.9
- Properties to include: Choose the property that holds your _Full Name_ values and give it key _input\_string_
- Code: Copy and paste the provided code
- Data output: Create two data outputs as string values and call the _first\_name_ and _last\_name_

 ![Screenshot 2023-01-12 at 09.13.03.png](https://d2qpr2jzcazej7.cloudfront.net/original/2X/d/d7c9dd9f9f9292c38a96727e36ee63eb112927b5.png)

 ![Screenshot 2023-01-12 at 09.13.17.png](https://d2qpr2jzcazej7.cloudfront.net/original/3X/9/5/95a11461b362a020bac8a8f1d7e888e9a5e9a5f4.png)

You then can test it with a contact.

To use it in the _First Name_ and _Last Name_ properties, create two additional workflow actions with _Copy Property Value._ Here you can copy the value from the output strings to the respective property.

 ![Screenshot 2023-01-12 at 09.14.07.png](https://d2qpr2jzcazej7.cloudfront.net/original/3X/d/7/d74797bb554117e30137aa426ec8d77c59552e84.png)

If you found this post helpful, consider helping others in the community to find answers faster by marking this as a solution. I’d really appreciate it.

Cheers,

Chriso

---

<div class="post-metadata">

**Author:** ![ShlomiGani](https://avatars.discourse-cdn.com/v4/letter/s/7ab992/32.png) [@ShlomiGani](https://community.hubspot.com/u/ShlomiGani)\
**Post date:** [January 12, 2023, 10:22am UTC](https://community.hubspot.com/t/custom-code-format-data-split-full-name-property/72665/6 "2023-01-12T10:22:43Z")

</div>

Amazing.

Thank you very much 🙂

I really appreciate it

---

<div class="post-metadata">

**Author:** ![ShlomiGani](https://avatars.discourse-cdn.com/v4/letter/s/7ab992/32.png) [@ShlomiGani](https://community.hubspot.com/u/ShlomiGani)\
**Post date:** [January 12, 2023, 12:44pm UTC](https://community.hubspot.com/t/custom-code-format-data-split-full-name-property/72665/7 "2023-01-12T12:44:04Z")

</div>

@ChrisoKlepke  
There are some names that have more than one word, so I changed the code so the first name will be the first word, but the last name will be the rest

`last_name = full_name.replace(first_name, "")`

---

<div class="post-metadata">

**Author:** ![ChrisoKlepke](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/chrisoklepke/32/11213_2.png) [@ChrisoKlepke](https://community.hubspot.com/u/ChrisoKlepke)\
**Post date:** [January 12, 2023, 12:57pm UTC](https://community.hubspot.com/t/custom-code-format-data-split-full-name-property/72665/8 "2023-01-12T12:57:49Z")

</div>

@ShlomiGani yeah, I was expecting such a problem. The issue I see is that you never know if it is two first names or last names. Maybe depending on the culture you’re operating in, one or the other is more likely. But in any case: The way you’re suggesting makes sure nothing gets lost.  
The other approach could be to write an if condition in the code that returns the main function and notifies a team member to take care of that manually. Of course, doesn’t scale that well.  
What I’m trying to say is that no solution is entirely foolproof and there are advantages and disadvantages to everything. Thank you for the feedback and conversation, though.

Cheers,

Chriso

---

<div class="post-metadata">

**Author:** ![LRiley32](https://avatars.discourse-cdn.com/v4/letter/l/ebca7d/32.png) [@LRiley32](https://community.hubspot.com/u/LRiley32)\
**Post date:** [May 17, 2023, 7:08pm UTC](https://community.hubspot.com/t/custom-code-format-data-split-full-name-property/72665/9 "2023-05-17T19:08:46Z")

</div>

@ChrisoKlepke

when implementing the code and “first name” contains only one name, it duplicates the first name to the last name.

Is there a way to prevent the code from running if there is no space and last name?

---

<div class="post-metadata">

**Author:** ![MHarp](https://avatars.discourse-cdn.com/v4/letter/m/df788c/32.png) [@MHarp](https://community.hubspot.com/u/MHarp)\
**Post date:** [January 5, 2024, 11:27pm UTC](https://community.hubspot.com/t/custom-code-format-data-split-full-name-property/72665/10 "2024-01-05T23:27:03Z")

</div>

Hi Christoph, I have done as you show in the screenshots and get this error message :

Property to include in code is input\_string  
My two outputs are first\_name, last\_name  
Language is python 3.9 and I have the property correctly mapped to include in code. Copied and pasted verbatim from above.

```auto
[ERROR] AttributeError: 'NoneType' object has no attribute 'split'
Traceback (most recent call last):
  File "/var/task/hubspotHandler.py", line 4, in hubspot_handler
    return file.main(event)
  File "/var/task/file.py", line 5, in main
    name_list = full_name.split(" ")
Memory: 37/128 MB
Runtime: 10.59 ms

```

---

<div class="post-metadata">

**Author:** ![Pferrara](https://avatars.discourse-cdn.com/v4/letter/p/c68b51/32.png) [@Pferrara](https://community.hubspot.com/u/Pferrara)\
**Post date:** [May 20, 2025, 10:16pm UTC](https://community.hubspot.com/t/custom-code-format-data-split-full-name-property/72665/11 "2025-05-20T22:16:45Z")

</div>

hi do i need operations hub for this?

---

<div class="post-metadata">

**Author:** ![kennedyp](https://avatars.discourse-cdn.com/v4/letter/k/49beb7/32.png) [@kennedyp](https://community.hubspot.com/u/kennedyp)\
**Post date:** [June 2, 2025, 10:07pm UTC](https://community.hubspot.com/t/custom-code-format-data-split-full-name-property/72665/12 "2025-06-02T22:07:02Z")

</div>

Yes. [Custom code workflow actions](https://developers.hubspot.com/docs/reference/api/automation/custom-code-actions#custom-code-workflow-actions) require Operations Hub - Professional or higher.
