Skip to content

Instantly share code, notes, and snippets.

@jackcoldrick90
Last active March 8, 2022 12:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jackcoldrick90/1f4496bdc37d78cb101cae65a318a2a8 to your computer and use it in GitHub Desktop.
Save jackcoldrick90/1f4496bdc37d78cb101cae65a318a2a8 to your computer and use it in GitHub Desktop.
This script is designed to be used within a custom coded workflow action (Operations Hub Professional) and adds the appropriate suffix depending on the day of the month. It relies on you already having the date stored in a single line text property DD/MM/YYYY. Worth noting this assumes you are storing the date in DD/MM/YYYY format. If you are us…
const hubspot = require('@hubspot/api-client');
exports.main = (event, callback) => {
const hubspotClient = new hubspot.Client({
apiKey: process.env.HAPIKEY
});
hubspotClient.crm.contacts.basicApi.getById(event.object.objectId, ["selected_date"])
.then(results => {
// depending on the date format you have setup you may need to adjust this. This assumes format DD/MM/YYYY
let selectedDate = results.body.properties.selected_date.split(" ");
let dayNow = selectedDate[0];
let monthNow = selectedDate[2];
let daySuffix = "";
switch (dayNow) {
case "1":
case "21":
case "31":
daySuffix = "st";
break;
case "2":
case "22":
daySuffix = "nd";
break;
case "3":
case "23":
daySuffix = "rd";
break;
default:
daySuffix = "th";
break;
}
let updatedDate = dayNow + daySuffix + " of " + monthNow;
callback({
outputFields: {
updatedDate: updatedDate
}
});
})
.catch(err => {
console.error(err);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment