Skip to content

Instantly share code, notes, and snippets.

@HubSpotHanevold
Created June 27, 2025 18:34
Show Gist options
  • Save HubSpotHanevold/4753af549093cf33761c2ad70d973800 to your computer and use it in GitHub Desktop.
Save HubSpotHanevold/4753af549093cf33761c2ad70d973800 to your computer and use it in GitHub Desktop.
exports.main = async (event, callback) => {
/*****
Use inputs to get data from any action in your workflow and use it in your code instead of having to use the HubSpot API.
*****/
const callNote = event.inputFields['hs_call_body'];
// Step 1: Split the string into key-value pairs
const keyValuePairs = callNote.split(';');
// Step 2: Store values in variables
let contactId, agentEmail, programName, skillName, fromNumber, leadPhone, notes, attempts, niceOriginalCreatedDate;
keyValuePairs.forEach(pair => {
const [key, ...rest] = pair.split(':');
const value = rest.join(':').trim(); // Rejoin in case the value had colons
const trimmedKey = key.trim();
switch (trimmedKey) {
case 'CONTACT ID':
contactId = value;
break;
case 'AGENT EMAIL':
agentEmail = value;
break;
case 'PROGRAM NAME':
programName = value;
break;
case 'SKILLNAME':
skillName = value;
break;
case 'FROM NUMBER':
fromNumber = value;
break;
case 'LEAD PHONE':
leadPhone = value;
break;
case 'NOTES':
notes = value;
break;
case 'ATTEMPTS':
attempts = value;
break;
case 'NICE ORIGINAL CREATED DATE':
niceOriginalCreatedDate = value;
break;
}
});
if(niceOriginalCreatedDate) {
// Step 1: Create a Date object in Central Time by parsing manually
const dateParts = niceOriginalCreatedDate.match(
/(\d{1,2})\/(\d{1,2})\/(\d{4}) (\d{1,2}):(\d{2}):(\d{2}) (AM|PM)/
);
if (!dateParts) {
// either skip the date logic or throw a more helpful error
throw new Error(`unexpected date format: ${niceOriginalCreatedDate}`);
}
let [, month, day, year, hour, minute, second, meridian] = dateParts;
month = parseInt(month, 10) - 1; // JS months are 0-based
day = parseInt(day, 10);
year = parseInt(year, 10);
hour = parseInt(hour, 10);
minute = parseInt(minute, 10);
second = parseInt(second, 10);
// Convert to 24-hour format
if (meridian === "PM" && hour !== 12) hour += 12;
if (meridian === "AM" && hour === 12) hour = 0;
// Create a Date object in Central Time, then adjust to UTC
const create_in_unix = Date.UTC(year, month, day, hour + 5, minute, second); // CDT = UTC-5
console.log(contactId);
console.log(fromNumber);
console.log(niceOriginalCreatedDate);
console.log(create_in_unix);
console.log(attempts);
callback({
outputFields: {
contactId,
fromNumber,
create_in_unix,
attempts,
dateknown: true
}
});
} else {
callback({
outputFields: {
contactId,
fromNumber,
attempts,
dateknown: false
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment