MEDTECH

Global HubSpot lead routing the sales team can manage

A global life sciences company with sales teams across North America and Europe.

The challenge

Over 100 territory rules inside one block of code

Every new contact needed to reach the right sales rep, and the rules for deciding who that was changed from one market to the next. In the United States, territories were set by zip code, with several reps sharing a single metro area. Elsewhere in North America the split was by state. In Europe, some reps covered a whole country, some covered several, and in at least one country the territory was divided by region.

All of that logic lived in a single custom code action inside a HubSpot workflow. It had been written some years earlier and ran to tens of thousands of characters. Rep IDs, long strings of zip codes and the order in which rules were checked were all written into the code itself, and some of them appeared in more than one place. The code had grown as the sales team changed around it.

The context

One small mistake could stop leads reaching anyone

Changing a single territory meant finding every place it appeared and editing the code by hand. A missing comma, a stray quote mark or a zip code pasted into the wrong list could break the whole action, or quietly send leads to the wrong rep. Nothing would flag the error at the time of the edit. The first sign would be a rep asking why their leads had dried up, or a new lead sitting with nobody.

Nobody could see who owned what
There was no simple view of a rep's territory. To answer a basic question such as "which zip codes does this rep cover?" someone had to read through the code and piece it together. Overlaps between reps were hidden in the order of the code, so a territory could end up claimed twice without anyone noticing. Sales leadership had no way to review the territories without asking someone technical to explain them.

“

I'm over the moon, Carl, I really am.

ML
HubSpot team, global life sciences company
What we did

A rules table in HubDB and a small code action that never needs editing

01
Moved every rule into a HubDB table
HubDB is HubSpot's built-in database tool, and it was already part of the company's HubSpot subscription. We created a single table to hold the routing rules. Each row is one rule: the rep who should receive the contact, what to match on and the values to match.A rule can match on country code, country name, state or region code, or zip code. That covers every pattern the business uses, from a rep with a whole European country to a rep with a list of zip codes in one city. Our team took the existing code apart, worked through it rule by rule, and rebuilt it as just over 100 rows in the table.
02
Set the order rules are checked in
Some territories overlap. A rep might own specific zip codes in a state while another rep picks up the rest of that state. Each row has a check order, so the most specific rules are tested first and the broad catch-all rules sit at the bottom. We left gaps between the check order numbers, so a new rule can be slotted in between two existing ones without renumbering the table.
03
Made the table easy to read and maintain
Reps are listed by name, so nobody has to look up owner IDs. A notes column records why a rule exists or when it changed. Each rule can be switched off without being deleted, which also means the team can keep a short history when a territory moves from one rep to another and tidy it up later.Filtering the table by a rep's name shows every rule they own in seconds. The whole table can be exported to a spreadsheet for sales leadership to review, then imported back once changes are agreed.
04
Replaced the old code with a short, fixed code action
The workflow keeps the same enrolment criteria. The custom code action now does one thing: it reads the published HubDB table, works through the rules in check order and returns the matching owner. All of the routing logic now lives in the table, so the code action only needs to change if the business adds a new type of rule.
The outcomes

Territory changes in minutes, without a developer

100
ROUTING RULES

Every territory across North America and Europe held in one table, in check order.

0
LINES OF CODE TO EDIT

Territory changes are made in the table. The code action stays as it is.

£0
EXTRA SUBSCRIPTIONS

Built with HubDB and workflows the company already had in HubSpot.

What came next

Tested by the team, then live

The new routing was built and tested in the company's sandbox portal and handed to the sales operations team to review with sales leadership. Once they are happy with the rules, it moves to the live portal.
"I think that will probably solve the issue and make it so much easier to manage."
HubSpot team, global life sciences company"I can run it through with the team, watch them hopefully light up as much as I just have."
HubSpot team, global life sciences company
If the business ever wants a dedicated marketplace app later, the rules are already clean, documented and ready to move

← Back to all work
The service used
Revenue Reset

A structured diagnostic that maps exactly where your HubSpot architecture is breaking down and produces a prioritised blueprint for what needs to change.

Learn about the Revenue Reset →
Start with a diagnostic

Every engagement starts with a Revenue Reset.

A structured diagnostic that maps exactly where your HubSpot architecture is breaking down and produces a prioritised blueprint for what needs to change.
Book a Revenue Reset →
Fixed scope No ongoing commitment
Delivered in 2–3 weeks

"A Revenue System Health Score and a Revenue Architecture Blueprint specific enough to present to your board or your investors as a plan of action."