Tips, Tricks & Best Practices for Programmable Automation

With the launch of our Operations Hub, we wanted to share a few tips and tricks with you for the brand new Programmable Automation and Data Quality Automation features. If you haven’t heard about these exciting new features yet, you can check out Jesse Tremblay’s post to give you a quick introduction.

We will be keeping this up to date and will continue to add new tips, tricks and educational resources so that you can find it all in one place. Feel free to add your own in the comments section below!

Tip 1. Create a secrets library

With the Custom Code Action, you can call out to other API services as a part of your workflow. In order to make this as seamless as possible we’ve also made it easy to securely store the API secrets that allow you to authenticate into those services. You can now store, manage, and reference multiple secrets, including your HAPIKEY, within the Custom Code Action in HubSpot!

To do this, create a workflow and add a Custom Code Action to it. At the top of the panel there is a “Secrets” section where you can add, edit, or delete your secrets. You can choose to add a Secret within the Custom Code Action or by clicking “Manage Secrets” to go to the Secrets management modal.

When adding secrets, make sure to give them a descriptive name to help differentiate them so others can easily use them. Also, remember that when you are referencing them in your code it is case sensitive.

Once you’ve added the Secret, you can then select it in the Custom Code Action and see how to use it in your code.

While you can’t edit the name, you can edit the value of the secret. Any edits will update any workflows that reference them, so there’s no need to scan through every workflow looking for any references to that secret.

Tip 2. Add context to your custom code

The Custom Code Action is one of the more complex and flexible actions we have available to our users, so we want to make it as accessible as possible for everyone who uses workflows.

One way you can do this is by leaving a comment on your Custom Code action in the workflow. When adding Custom Code to a workflow, it’s not always clear from the workflow view or to everyone who uses workflows to know what that action is doing. By adding comments, you can simplify this for everyone.

Another way to do this is by describing your code. This makes it easier for your peers to add to, review, help troubleshoot, and understand the actions that are taking place. You can add comments in your code using “//” before the comment, like this:

Tip 3. Add custom log messages to make troubleshooting easier

Troubleshooting why something isn’t working correctly can be tedious and time-consuming. One way to make this easier for you and your team is to add custom log messages to your code to make it clear what is (or isn’t) happening.

You can add logs like this:

42574i444456141E98D467.png

You can then view these logs in the Event Details in the History tab of the workflow. This will make it easier for anyone to understand what is happening within a custom code workflow. We recommend working with your peers who will be managing or reviewing these workflows to understand what logs would be the most helpful.

Tip 4. Defining Outputs

Once you’ve written your custom code, you can define an output that will be returned that you will then want to use later on in your workflow. This allows you to generate outputs that you can use as an input in a later action without needing to do additional API calls. This can help you avoid hitting your API limits with HubSpot and with other services or apps!

To do this, at the bottom of the Custom Code Action panel, you can select the Data type and provide the name of the output.

You can then use this output in another action later on in your workflow. To do this, add a new action and find the Custom Code output in the “Property” dropdown:

Once your workflow is on, you can see the values that are being returned for that output in the history tab in the workflow. Just click to see the event details on the Custom Code Action and look at the “Return value” section.