Custom Code Workflow Actions Explained:
Automated Deal Renewals in HubSpot Workflows
Automatically create renewal deals, clone recurring line items, and generate quotes—all in one workflow action.
What This Workflow Does
This combined renewal workflow handles the entire renewal process in a single custom code action:
- Validates recurring line items – Only creates renewals for deals with recurring billing
- Creates a renewal deal – With calculated close date and inherited properties
- Associates company and contacts – Carries over relationships from the original deal
- Clones only recurring line items – Copies only recurring items (configurable)
- Generates a quote – Creates a CPQ or legacy quote with all associations
This tutorial assumes you've read the Kickbox workflow tutorial and understand the basics of custom code actions.
Before You Start
You'll need:
- Operations Hub Professional or Enterprise – Required for custom code actions
- A deal-based workflow – Triggered when deals meet your renewal criteria
- A renewal pipeline + stage set up
- A quote template – Either CPQ or legacy template ID
Optional Custom Properties
The workflow supports these optional deal properties. If they don't exist in your portal, set the corresponding config variable to null:
autorenew– Boolean to track auto-renewal statusparent– String property to store the original deal ID
Note: The workflow automatically handles missing properties—if a property doesn't exist, it retries without it.
Configuration Variables
At the top of the code, configure these constants to match your HubSpot setup:
Step 0: Check Recurring Line Items
Before creating anything, the workflow validates that the deal has recurring line items. If not, it exits early—no renewal needed.
Key Points
- Early exit pattern – Returns immediately if no recurring items found
- Amount calculation – Sums only recurring line items for the renewal deal amount
- Renewal date logic – Uses the longest billing term to calculate when the renewal is due
The billing frequency mapping converts HubSpot's internal values to months:
Step 1: Create Renewal Deal
Creates a new deal in the renewal pipeline with properties from the original deal. The code includes automatic retry logic that removes optional custom properties if they don't exist in your portal:
Step 1b: Associate Company and Contacts
Carries over the primary company and all contacts from the original deal:
Step 2: Clone Line Items
Clones recurring line items to the new deal. By default, one-time items are skipped:
Step 3: Create Quote
Creates a quote and associates it with the deal, line items, contacts, and company. For CPQ quotes, it also sets a signer:
Association Type IDs
The quote needs several associations. Here are the type IDs used:
| Association | Type ID |
|---|---|
| Quote → Template | 286 |
| Quote → Deal | 64 |
| Quote → Line Item | 67 |
| Quote → Contact | 69 |
| Quote → Company | 71 |
| Quote → Signer (CPQ) | 702 |
Complete Code
Here's the full workflow code. Copy this into your custom code action:
Using the Output
The workflow outputs two values you can use in subsequent actions:
NewDealID– The ID of the created renewal dealquoteID– The ID of the generated quote
Workflow Input Fields
Map these deal properties as input fields in your workflow action:
| Input Field | Property | Required |
|---|---|---|
| hs_object_id | Deal ID | Yes |
| dealname | Deal name | Yes |
| closedate | Close date | Yes* |
| hubspot_owner_id | Deal owner | Yes |
| deal_currency_code | Currency | Yes |
| autorenew | Auto-renew flag | No |
| renewal_date | Renewal date | No* |
| description | Description | No |
| hs_analytics_source | Original source | No |
| hs_mrr | Monthly recurring revenue | No |
| success_owner_id | Success owner | No |
| contract_owner_id | Contract owner | No |
| hs_all_assigned_business_unit_ids | Business unit IDs | No |
*Either closedate or renewal_date is required to calculate the renewal deal's close date. If renewal_date is provided, it's used directly. Otherwise, the close date is calculated from closedate plus the longest billing term from recurring line items.
Ready to Automate Renewals?
Copy the code above and create your first renewal workflow. Check out our other tutorials for more workflow automations.
View All Tutorials Kickbox Tutorial