Skip to content

Instantly share code, notes, and snippets.

View HubSpotHanevold's full-sized avatar

Tyler Hanevold (HubSpot) HubSpotHanevold

View GitHub Profile
@HubSpotHanevold
HubSpotHanevold / sample.html
Created June 12, 2024 19:53
Putting calendar meeting times into an email
{# NOTE THESE CAN ALL BE ADJUSTED TO USE PLACEHOLDER VALUES INSTEAD OF DEFINED IN THE CODE #}
{# START AND END TIMES FOR THE EVENT #}
{% set google_start_time = "T230000Z" %}
{% set google_end_time = "T240000Z" %}
{% set outlook_start_time = "T23:00:00+00:00"|urlencode %}
{% set outlook_end_time = "T24:00:00+00:00"|urlencode %}
{# STATIC VALUES - DEFINED #}
{% set event_title = "Sample webinar title"|urlencode %}
@HubSpotHanevold
HubSpotHanevold / gist:2c341624ba9ba17d446146581c12a21c
Last active July 22, 2024 19:12
Convert html in rich text to friendly text
exports.main = async (event, callback) => {
let originalString = 'TEXTGOESHERE';
let updatedString = originalString.replace(/<br>/g, ';')
let nextupdatedString = updatedString.replace(/<(?=\s*[^a-zA-Z\/])/g, '****');
let nextnextupdatedString = nextupdatedString.replace(/<[^>]*>|#nextsteps|&nbsp;/g, '')
let finalString = nextnextupdatedString.replace(/\*\*\*\*/g, '<');
<script>
document.addEventListener("DOMContentLoaded", function() {
// Wait for the form to load
setTimeout(function() {
var urlInput = document.querySelector('input[name="url_of_page"]');
if (urlInput) {
console.log('url_of_page input exists');
urlInput.value = window.location.href;
}
},1000); // Adjust the delay if needed
exports.main = async (event, callback) => {
var phone = event.inputFields['phone'];
console.log("Input Phone: ", phone)
const outputFields = {
valid: false,
validation_message: "",
phone: ""
}
@HubSpotHanevold
HubSpotHanevold / check api limit.js
Created August 21, 2024 16:51
A simple custom coded action to check API limits in workflows.
const axios = require('axios');
exports.main = async (event, callback) => {
const auth = 'Bearer ' + process.env.CHANGE_THIS_VALUE_TO_MATCH_YOUR_SECRET_NAME;
const email = event.inputFields['email'];
let data = JSON.stringify({
"filters": [
{
<script>
document.addEventListener("DOMContentLoaded", function() {
setTimeout(function() {
const emailInput = document.querySelector('input[name="firstname"]');
emailInput.addEventListener("input", function() {
const emailPattern = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
const parentDiv = emailInput.closest('.input');
let messageDiv = parentDiv.querySelector('.email-error');
exports.main = async (event, callback) => {
var phone = event.inputFields['phone'];
console.log("Input Phone: ", phone)
const outputFields = {
valid: false,
validation_message: "",
phone: ""
}
import requests
url = "api.hubspot.com/events/v3/events/?objectType=contact&objectId=52054635672"
payload = ""
headers = {
'Authorization': '••••••'
}
response = requests.request("GET", url, headers=headers, data=payload)
@HubSpotHanevold
HubSpotHanevold / script.js
Created November 7, 2024 00:46
Using typeahead on a HubSpot form
// include the following scripts that can be found here https://select2.org/getting-started/installation
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/select2.min.css" rel="stylesheet" />
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/select2.min.js"></script>
// in the below, we listen for the form to load, then switch out the standard select element (by name) with a select2 element
<script>
window.addEventListener('message', event => {
if(event.data.type === 'hsFormCallback' && event.data.eventName === 'onFormReady') {
// Initialize Select2 on the specified select element - update with the internal name of the property where it says internal_select_name
const selectElement = $('select[name=internal_select_name]').select2();
@HubSpotHanevold
HubSpotHanevold / script.js
Created November 7, 2024 17:15
Melissa Data Integration
<script>
window.onload = function () {
// Function to poll for the existence of the input field
function waitForElement(selector, callback) {
const inputField = document.getElementsByName(selector)[0];
if (inputField) {
callback(inputField);
} else {
setTimeout(function () {
waitForElement(selector, callback);