HubSpot Workflow Custom Code Actions: My Take on "Input" and "Output"
If you've ever used HubSpot workflows, you might have found yourself thinking, "It’d be so cool if I could automate *this* too! 🥺" I know I did! So I dove into custom code actions, feeling excited about all the possibilities. But then I already got stuck before I even started coding, I was like, “Wait… why do I have to define names and variables so many times? What’s going on here?" 😂
After taking some time to really get my head around it, I think I’ve figured it out! Today, I’m going to share my understanding of how "input" and "output" work in custom code actions.
From what I gathered from testing:
- Pull in values from the previous action using the "Properties to include in code" field
- This is kind of like the setup phase. You grab the values you want to work with, whether they’re from a CRM record or from a previous action in your workflow.
- Assign these values to variables in the custom action code
- Next, you assign those values to variables in your JavaScript or Python code so you can actually use them.
- For example, in event.inputFields['property_in_code'], you’re taking the value you pulled earlier in the "Properties to include" field and assigning it to a variable. Now you’re ready to work with that data!
- Give the output a name
- Once you’ve worked with the data, you need to give the result a name. By setting it in the `callback({ outputFieldName })` structure, you’re telling the system, “This is the value I want to pass on to the next action.” It’s kind of like labeling it so the next step can recognize it.
- Define the data type for each output
- Finally, you need to specify what kind of data you’re outputting.
- For example, let's says you got a value like 1691359627 in your codes - I believe the system would like to know whether it’s a timestamp or just a regular number, since that can affect how the next action handles it.
- As you might know, this step won’t automatically update the CRM property even if the internal property name and the output field name are the same,.
- You’ll need to separately set up a "Copy property value" action to push data (back) into the CRM.
Additional notes
When we're assigning values to variables or setting up output, you can also update or add values. I explain this, along with some examples of what worked (and what didn’t 😅) in my Japanese video. I'll work on the English version when I have some time🤗
After testing out:
This is just how I personally feel, but understanding input and output in HubSpot’s custom code actions really helps when you’re troubleshooting those "undefined" errors. I hope sharing my thoughts here clears up some confusion if you’ve been feeling the same way!
*Please note that this is based on what I tested as of August 2024.*