Feb 10, 20212:48 PM - last edited on May 7, 202110:06 AM by jbogaert
HubSpot Employee
Data types for outputs (with sample code!)
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.
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":
Booleans are true/false values. In HubSpot, single-checkbox properties fulfill this role. You can only store boolean values in single-checkbox properties.
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
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
Can I use data output from Custom Code in Value Equal Branch imedialtey without using Copy Property Value Action? I am trying to use Value Equal Branch for handling boolean Data output but the excution always goes to "Not Meet" branch.