• Got questions about HubSpot’s Smart CRM?

    Our product team is answering them live through March 6th!

    Ask us anything
  • Ready to build your local HubSpot community?

    HUG leaders host events, spark connections, and create spaces where people learn and grow together.

    Become a HUG Leader

Workflow custom code setting date issue

RHussein
Member
I have a workflow where I take an HS date field (deal created date) and set it to a new date variable using custom code. Only passing the date variable through the custom code results in setting 'Invalid date'.The actual use case is more complex than just passing data through custom code: getting the minimum of multiple dates with specific fallbacks and rules. So, I need the custom code but I can't get the simple version to work. Attempts so far:
  • Set to deal create date: success
  • Set to custom code output: Invalid date
  • Set to format of custom code output: Invalid date
Please advise

Custom code:

def main(event):
try:
# Retrieve all relevant fields (do not alter the dates)
created_date = event["inputFields"].get("createdate", None)

# Return output fields without altering the date values
return {
"outputFields": {
"created_date": created_date
}
}

except Exception as error:
# Handle unexpected errors
return {
"outputFields": {
"created_date": None,
"error": str(error),
}
}Screenshot 2025-02-14 at 16.21.40.pngScreenshot 2025-02-14 at 16.22.18.pngScreenshot 2025-02-14 at 16.22.30.pngScreenshot 2025-02-14 at 16.22.47.pngScreenshot 2025-02-14 at 16.23.30.png

0 Upvotes
1 Accepted solution
nickdeckerdevs1
Solution
Top Contributor | Gold Partner
Top Contributor | Gold Partner

For formatting dates: YYYY-MM-DDT00:00:00.000Z
This is ISO 8601 formatting, if the property is only a DATE property, the time needs to be set to midnight in UTC, Same with DATETIME, except you set the time not at midnight, your actual time.

Now this is how you input it via the api.

Since you are already in a custom code block, just add your api call to update that record property!

I've never had a lot of success setting a date or datetime inside a workflow. I just break out the api update.

View solution in original post

1 Reply 1
nickdeckerdevs1
Solution
Top Contributor | Gold Partner
Top Contributor | Gold Partner

For formatting dates: YYYY-MM-DDT00:00:00.000Z
This is ISO 8601 formatting, if the property is only a DATE property, the time needs to be set to midnight in UTC, Same with DATETIME, except you set the time not at midnight, your actual time.

Now this is how you input it via the api.

Since you are already in a custom code block, just add your api call to update that record property!

I've never had a lot of success setting a date or datetime inside a workflow. I just break out the api update.