Date Format For Setting Dates In Workflows


Workflow

Error

Custom Code Action

CCA TestHey folks! I’m trying to use a Custom Code Action to generate a date 60 days from the date of workflow execution, and then copy that to a date picker property (using the copy value to property action). However, no matter what format I set the date as in the CCA, I get a “property value isn’t valid” error.

Does anyone know for sure exactly what the format needs to be in copying a date from a CCA to a field without using the API? I’m trying to minimize my API impact here if possible. I haven’t yet found any hints to the correct one online, and there are almost an infinite number of possibilities here.

Hi @ArdenM,

Thanks for reaching out!

Can you include a screenshot of your workflow and the error message so the community can better assist with the next steps?

Thank you!

Best,

Kristen

Hi @kvlschaefer

I’ve added screenshots of the workflow, error message, custom code action, and the current CCA output to the original post.

The enrolment criteria has a record id for testing purposes, and the CCA lacks a hubspot client because it’s not accessing the API at all.

Thanks for taking a look!

Hey folks - after some back and forth with support I was eventually able to solve this. There are two main ways to accomplish my own goal of “set a date X days into the future and copy it to a date picker field”.

1

The first, building off the workflow above, is to output the code-generated date as a UNIX timestamp (using miliseconds specifically - UNIX standard is seconds, but HubSpot uses miliseconds). Easiest way to do this with JS is

Math.floor(dateVariableName.getTime())

Output that value as a number variable, then use the Format Data action to coerce it to a date by using “plus_time” and adding 0 days (or any other measurement of time). As HubSpot stores its dates as UNIX timestamps anyway, it will correctly read the date, and you can use the output as a date value for a date picker.

2

If you don’t care about using a Custom Code Action to generate the date in the first place (i.e. you only need a simple date add/minus like here) you can achieve the same outcome without Custom Code.

Set a date field to the date of step using the Set Property action, take that date field and Format data to or remove the number of days, and then push that to the final date field you’re looking to set. This is by far the simpler method if you don’t have complex calculations needed to generate your date.

Thanks for sharing the outcome @ArdenM , I wasn’t aware of what the format data action does/can do and it totally solved my use case (creating yesterday’s date and tomorrow’s date properties from a today’s date property created using a time stamp).

Unix timestamp that is output from the Custom Code must adhere to the type of the property you’re willing to set. If it’s Date type and not Datetime then a Unix timestamp containing hours will evaluate to invalid format, and should be converted to a date only timestamp.

Date.parse(‘2024-06-20T10:10:27.188Z’) → 1718878227188 → INVALID

Date.parse(‘2024-06-20’) → 1718841600000 → OK