Back to Top

Streamline Contract Renewals: HubSpot Hacks for Seamless Automation

Picture of Viktor Olsson Viktor Olsson |

Minuters läsning

Looking to streamline contract renewals and gain an overview that saves time and minimizes manual work? You're in the right place! Today, we will delve deep into the world of HubSpot Hacks with a focus on Operations Hub. We'll explore an exciting method for automating and correcting dates with custom code. Join us as we guide you through the steps to create a smooth and efficient process for contract renewals that could revolutionize your business! In this week's blog, there will be a little more hands-on HubSpot Hacks, with a focus on the custom code part of Operations Hub!

Content:

  1. Custom Code - adjust dates automagically!

 

Step 1:
We need a reason to create the upcoming automation.

In our example, we will use a custom object called "Vendor Contracts". We are creating this custom object to be able to follow up and get a good overview of our contracts with our suppliers.

Step 2:

Once inside each contract, we will be able to create fields that are relevant for getting a good overview:
We would like to be able to do the following:

  • Contract type 
  • Service type 
  • Contract start date
  • Contract end date
  • Contract days remaining
  • Notice period
  • Last notification (months)
  • Contract renewal months
  • Auto renew = Om det är en kontrakt som automatiskt förnyas tills att det sägs upp

 


 

Here comes the exciting part! Workflow #1

To do this automatically, we need to use HubSpot's own workflow and custom code features. But before we get to custom code, we need to make sure a few other things work first!

1. We need to know first that it is time to trigger a renewal - we do this in workflow #1.

Kriterierna för detta är:

  1. End-date must be known
  2. Today's date must be known
  3. It is less then 1 day remaining on the contract (Today's date - contract end date)
  4. Auto renew must be "yes"
  5. Time to renew must be "no" in order to avoid a loop

If all of these are met you trigger a set property action - set time to renew to "yes"

 

Workflow #2


In workflow number 2, we then need to look at whether similar requirements are met.

  1. Auto renew = yes
  2. Today's date = is known
  3. Contract end date = known
  4. Contract renewal month must be known as this be decide how many months it will renew at time.
  5. Time to renew = yes (Remember: this was set in the previous workflow)

 


As step 2 in the same workflow, you create a branch. In this branch, you look at contract renewal months. This is because you will need to adjust the flow accordingly depending on how many months it should be renewed. In this example, you will look at 1 month.

 

 

 

Now it starts to get exciting! First, we will need to format the contract start date and add 1 month to the current contract start date and save it to the same property. We add one month because contract renewal months is set to 1. This is also where it differs per branch, depending on how many months you want to increase at a time, a branch is required for each "scenario".

 

 

 

 

Next, we will do the same thing on the contract end date, we add one month and save it back to the same property. This is where we will need custom code because HubSpot does not care how many days there are in each month. So it becomes problematic if we have had a contract that has an end date of February 29th. If we add exactly 1 month (according to how HubSpot interprets it) we will get April 29th even though April has 30 days. We solve this with custom code!


So what we do now is we increase the contract end date by one month but we do not save it back to the property.

 

 

We will create a custom code action instead.

The settings that need to be made in this are shown in the next image under:

  • Language: Node.js 16.x
  • Description: Optional, but it is recommended to write a shorter explanation of what this particular one does.
  • Secrets: In this case, no secret is needed.
  • Property to include in code: Remember when we formated the contract end date? The output from that action is used here.
  • InputDate = contract end date (The formatted date from action 4)

 

copy the following code into the custom code module.

exports.main = async (event, callback) => {

  let inputDate = new Date(parseInt(event.inputFields['inputDate']));
  let newDateString = inputDate.getFullYear() + '-' + (inputDate.getMonth() + 2).toString().padStart(2, '0') + '-01 00:00:00 UTC';
  var newDate = new Date(Date.parse(newDateString));

  newDate.setUTCDate(newDate.getDate() - 1);

  console.log('Input date raw: ' + event.inputFields['inputDate']);
  console.log('Input date as Date: ' + inputDate);
  console.log('New date: ' + newDate);
  
  callback({
    outputFields: {
      outputDateString: newDate,
      outputDate: newDate, 

         }

    });
}

 

Almost done!

 

Bland det sista vi gör är att skapa en output. Vi behöver hämta ut det nya datumet och spara det i contract end date. Så för att lyckas med detta, klicka på "add output" och skapa en typ "date" och skriv sedan "outputTimeStamp".

 

 

 

 

 

 

 

In the last step, we perform a copy property action. We want to copy outputTimeStamp, which was the output from custom code. We want to save this in the contract end date.

 

 

 

 

 

 

 

There you go! You now have a functioning system to follow up on your contracts with the correct date :)

 

 

Would you like to know more about how we can build custom solutions for your specific problems?

  1. If this blog post has piqued your interest or if you're seeking guidance in HubSpot and CRM, don't hesitate to contact us.
  2. Follow us on social media. We continuously update on LinkedIn, Instagram, & Facebook whenever we have a new blog post. There, you'll find valuable tips and stay updated on news and valuable insights, so you lose nothing by following us!
  3. Would you like to connect on LinkedIn? You can find me here! Send a message about this topic or anything else!

/ Viktor Olsson - CRM Consultant

Läs mer

Why Businesses Should Be on TikTok: From Platform to Search Engine

Nov 15, 2024 3:00:32 PM

As a student in Social Media Marketing, TikTok is a topic I'm passionate about, and I’d like to share why it’s so important for businesses to have a...

EGC vs. UGC: What's the Difference and Why Does It Matter for Your Brand?

Nov 8, 2024 3:18:04 PM

Most people have heard of influencer marketing and UGC, but do you know what EGC is? Understanding the difference between Employer Generated Content...

How to use digital analytics in marketing.

Nov 1, 2024 10:41:20 AM

In an increasingly digital world, digital analysis has become a crucial part of marketing. This process helps companies understand how users interact...