We use cookies to make HubSpot's community a better place. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. To learn more, and to see a full list of cookies we use, check out our Cookie Policy (baked goods not included).
3 weeks ago
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 / 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)
Solved! Go to Solution.
3 weeks ago
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:
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.
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
3 weeks ago
Just noticing the title of the thread 😅 Here it is for full name getting first and last name.
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,
}
}
3 weeks ago
Hi Chrisotoph, Tnx for your quick answers.
Should I replace the green quets with the property lables?
As it is I get an eror .
[ERROR] AttributeError: 'NoneType' object has no attribute 'get' Traceback (most recent call last)
3 weeks ago
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:
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.
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
3 weeks ago
@Chriso-mwx
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, "")
3 weeks ago
@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
3 weeks ago
Amazing.
Thank you very much 🙂
I really appreciate it
3 weeks ago
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']
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