When you use data outputs in your custom-coded workflow, you give yourself the ability to use those outputs later in your workflow. In order for this to work, your code, the data type of the output, and the field type of the property you’re copying the value into all need to agree. This post will help you navigate these nuances.
String
You can put format pretty much any output as a string. I’ve successfully outputted strings, numbers, booleans, and dates as strings. It’s worth noting that the Copy Property Value action does some validation, here. When I outputed a JavaScript Date object into a String, the Copy Property Value action would only let me select date properties to copy to. Most often, you’ll copy strings to text properties.
OUTPUT OBJECT ID
exports.main = (event, callback) => {
callback({
outputFields: {
id: event.object.objectId
}
});
};
Number
Number outputs can be copied to number properties and also text properties. In general, number properties are a better way to go because you can filter contacts using “greater than,” “less than,” and “between”:
DIVIDE OBJECTS INTO 5 EVEN GROUPS BASED ON ID
exports.main = (event, callback) => {
callback({
outputFields: {
test: event.object.objectId % 5
}
});
};
Boolean
Booleans are true/false values. In HubSpot, single-checkbox properties fulfill this role. You can only store boolean values in single-checkbox properties.
EVALUATING SEVERAL BOOLEAN VALUES
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, ["property1", "property2", "property3", "property4", "property5"])
.then(results => {
let var1 = results.body.properties.property1;
let var2 = results.body.properties.property2;
let var3 = results.body.properties.property3;
let var4 = results.body.properties.property4;
let var5 = results.body.properties.property5;
callback({
outputFields: {
okToEmail: Boolean(var1 && var2 && var3 && var4 && var5)
}
});
})
.catch(err => {
console.error(err);
});
}
This example looks at five different single-checkbox fields and outputs
TRUE
if all of those values are true and outputs
FALSE
if any one of those properties is false or null. In HubSpot, there are several standard properties (Email Address Quarantined, Invalid Email Address, etc.) that could be used in an action like this.
Datetime
Fun fact: HubSpot has both datetime and date properties. When you create a “date picker” property using the UI, it’ll always be a date property (you can create custom datetime properties through the API). All standard date properties (e.g. create date) are actually datetime properties. Date and datetime properties look subtly different in the UI:
CALCULATE A DATETIME ONE YEAR AFTER A DATETIME PROPERTY
const hubspot = require('@hubspot/api-client');
exports.main = (event, callback) => {
const hubspotClient = new hubspot.Client({
apiKey: process.env.HAPIKEY
});
hubspotClient.crm.deals.basicApi.getById(event.object.objectId, ["closedate"])
.then(results => {
let expirationDate = new Date(results.body.properties.closedate);
expirationDate.setFullYear(expirationDate.getFullYear() + 1);
callback({
outputFields: {
expiration: expirationDate.getTime()
}
});
})
.catch(err => {
console.error(err);
});
}
This code is from a deal workflow that takes a deal’s create date and outputs a date that is one year later. Remember that standard properties like create date are datetime properties, so this outputs a datetime value. The example in the Date section below does the same thing but outputs it as a date value.
Enumeration
[Note currently working]
Date
As mentioned in the Datetime section above, HubSpot has both date and datetime properties. Any custom “date picker” properties you create in the UI with be date properties, while standard properties like Create Date will be datetime properties. This sample code is the same as the code in the Datetime section except for the added
expirationDate.setHours(0,0,0,0)
, which strips out the time so that the data can be outputted as a date and copied into a “date picker” property.
CALCULATE A DATE ONE YEAR AFTER A DATETIME PROPERTY
const hubspot = require('@hubspot/api-client');
exports.main = (event, callback) => {
const hubspotClient = new hubspot.Client({
apiKey: process.env.HAPIKEY
});
hubspotClient.crm.deals.basicApi.getById(event.object.objectId, ["closedate"])
.then(results => {
let expirationDate = new Date(results.body.properties.closedate);
expirationDate.setFullYear(expirationDate.getFullYear() + 1);
expirationDate.setHours(0,0,0,0);
callback({
outputFields: {
expiration: expirationDate.getTime()
}
});
})
.catch(err => {
console.error(err);
});
}


