HubSpot Community Blog

jbogaert
by: HubSpot Moderator
HubSpot Moderator

The Definitive Use Case Library For Programmable Automation In Operations Hub

Earlier this year, HubSpot introduced programmable automation in Operations Hub. With programmable automation, you can execute your own code in HubSpot workflows for the first time. Put simply, you can now automate anything you can imagine. 

 

But with so much flexibility, where do you even begin? To spark your imagination, we've pulled together this collection of use cases for programmable automation. Have questions about these use cases or examples of your own? Drop them in the comments below!

 

 

1. Associate a Contact to a Company

By Jack Coldrick

 

As you probably know, not all contacts that enter your CRM come with a business email address provided. They might not have one or prefered to enter their private email address. And so you end up with a bunch of orphaned contact records that you each have to painstakingly associate to a company object. Even if they filled out their company, HubSpot CRM only automatically associates based on the domain.

 

With this custom code action, you can automatically have contact be associated with a company based on the company name property that is stored on their contact record. If no matching company object is found, the code will create a new company record using the name of the contact’s company.

 

Code Snippet

https://gist.github.com/jackcoldrick90/faa4f25eb6f07a6bc50b84589a574b3d

 

2. Turn a Full Name into a First and Last Name

By Jack Coldrick

 

If you’re asking for the full name in a single field on a form, or if you’ve imported contacts that only have a full name, you probably know the pain it can cause for your marketing team’s personalized email sends. 

 

Instead of having to split these names manually, you can now use this custom code action to automatically populate HubSpot’s First Name and Last Name properties based on a record’s full name with great accuracy.  

 

Example

Input: { fullname: “Michael Scott”; firstname: empty; lastname; empty }

Output: { fullname: “Michael Scott”; firstname: “Michael”; lastname: “Scott” }

 

Code Snippet

https://gist.github.com/jackcoldrick90/6d854d0fe41a8b564bb4341f458d1bd2

 

Notes

The code is written on the following assumptions: the first name and last name are separated by a space, that the first name comes before the last name, and that the full name does not include a middle name.

 

Screenshot 2021-07-23 at 10.24.51.png3. Add a Date Suffix

By Jack Coldrick

 

This custom code action will increase the level of personalization in your automated emails. When you’re sending emails that include a date property, for instance for a trial expiry or a contract renewal, you can use this code snippet to attach the appropriate date suffix. Meaning “May 1” turns into “May 1st” and “November 5” becomes “November 5th”.

 

Code Snippet

https://gist.github.com/jackcoldrick90/1f4496bdc37d78cb101cae65a318a2a8

 

Notes

This code action is designed to be used in tandem with a date formatting action that will convert a MM/DD/YY date to text (e.g. “05/01/2021” to “May 1, 2021”). That format action will store the date in a single line text property which the code action can update with the appropriate date suffix. 

 

4. Format U.S. Phone Numbers

By Angus Gibbs

 

Having standardized phone numbers in your CRM can be a real must for your customer-facing team members. Not only will the increased readability improve the efficiency of your teams, it’ll also improve the operations of your systems. Data inconsistencies can create duplicates, break integrations or hamper reporting. 

 

With this custom code action, you can make sure that any 10-digit U.S. phone number is properly formatted as (XXX) XXX-XXXX, making your phone number easily readable and dependable.

 

Example

Input: { phonenumber: “1234567890” }

Output: { phonenumber: “(123) 456-7890” }

 

Code Snippet https://gist.github.com/angusgibbs/b144d78cf6d8a72ccce7a382436ee0d4#file-format_phone-js

 

5. Look Up Data in an External Database

By Jack Coldrick

 

Storing all of the user interactions on your platform in an external database? This custom code action can be used to integrate your CRM with your database. Its code will check whether a HubSpot contact exists in that database. The outcome of the code action can then be used to run all kinds of automations. For instance, when a contact converts on a form, you can have HubSpot check whether a contact uses your platform, and if they don’t, you can have it create a trial account for them. If they do, you can have it sync back their user information straight to their HubSpot contact record.

 

Code Snippet 

https://gist.github.com/jackcoldrick90/9d7301deb5c3ff42b24d40a3cda46686

 

Notes

The code is written to lookup data from the MySQL API. Looking up data from another external database is equally possible, but those lines of codes will need to be changed accordingly.

 

6. Validate Email Address Through a Validation Service

By Jack Coldrick

 

When you have a CRM that is littered with a bunch of fake or wrongly inputted email addresses, it can really harm your email marketing efforts and affect your ratings such as your Sendex score. With this code action you can automatically validate any email address in your CRM by running it through an email validation service such as Kickbox. Any email address deemed invalid can then be put into an exclusion list, which will help lower your bounce rates.

 

Code Snippet

https://gist.github.com/jackcoldrick90/cfdceb271cf14be70e441c6ee79849ef

 

 

7. Enrich your Company Data with a Business Intelligence Service

By Jack Coldrick

 

Having rich and correct data can make the difference between a deal that’s closed-won or closed-lost. Ensuring that your company data is always up to date and trustworthy is now something you can do with ease through HubSpot workflows. With this custom coded action you can query the ClearBit Company API to pull in information relating to the companies enrolled in the workflow and use that information to update your HubSpot CRM Company properties.

 

Code Snippet

https://gist.github.com/jackcoldrick90/b5e5e44a91a3a022b9b5720f1145930d

 

8. Enrolling a Custom Object’s Associations in Another Workflow

By sam-g

 

Whether it’s to store memberships, partners, contractors or territories, HubSpot’s custom objects can be used in many ways. Let’s say you use custom objects to store your company’s partners in your CRM, and those partners have many different contacts associated with them. With this custom code action you can run a workflow on the associations of any custom object. The code snippet will look at the custom object enrolled in the workflow, pull in any of its associations and push those over to another workflow of yours. For instance, a workflow for email marketing, or that will send out a notification to their owner, or that will update a property.

 

Code Snippet

https://community.hubspot.com/t5/9881-Operations-Hub/Finding-associations-and-then-adding-associated...

 

9. Weighted Lead Rotation

By Angus Gibbs

 

As opposed to having an evenly distributed lead assignment among your sales team members, you can use this code action to assign your leads in a weighted fashion. With this action you can decide what percentage of leads should go to each one of your sales reps, which is ideal when you have some high-performing reps that you want to assign more leads to, or if you have new reps that are still ramping up.

 

Code Snippet

https://gist.github.com/angusgibbs/b144d78cf6d8a72ccce7a382436ee0d4#file-format_phone-js

 

Notes

  • To get the owner ID of your HubSpot users, go to Settings -> Properties then search for  "Contact owner" and click "edit." The "owner ID" is the internal value for each user.
  • To use this value in your workflow, make sure you add an output to your custom code action with a data type of "enumeration" and a name of "owner_id" (no quotes). Then you can use a "Copy property value" action to update the object owner to the user selected by this code.
  • Since this is random, it is possible that the actual selections will not exactly match the given distribution (in the example, 40%/40%/20%). The more times the code is run, the closer it will be to the actual desired distribution (this is known as the "Law of Large Numbers"; see https://en.wikipedia.org/wiki/Law_of_large_numbers).
  • This should only be used in situations where it is acceptable if the actual selections are not exactly the chosen percentages.

 

10. Dynamically Update a Salesforce Campaign

By Robert Ainslie

 

If your organization is using SFDC Campaigns to keep track of all contacts and leads that come in touch with all your different HubSpot marketing motions, then you probably know the pain of integrating multiple campaigns with HubSpot. Instead of having to create a different workflow for every SFDC campaign, you can use this custom code action in a single workflow to dynamically update different Salesforce campaigns when leads and contacts visit your marketing offers.

 

Code Snippet

https://gist.github.com/robertainslie/8234976839aee86c6eeb6da8d3ee9db9

 

11. Count High-Value Line Items on a Deal

By Robert Ainslie

 

If you're working with deals that have many line items involved, it can be frustrating to not have a complete picture of the total value of those line items. Sure, you can create a custom report, but having a single deal property displaying the total sum of all high-value line items is a much easier solution. That's what this code action is able to do for you!

 

Code Snippet

https://gist.github.com/robertainslie/12314f50a8d2073f64a6ebef65953447

2 Comments
AJimenez8
Participant
JKrantz
Contributor

this is great!! thank you!