⚙ Operations Hub

svamann
Participant

Fetch and format date in Workflow

SOLVE

I have a workflow that fetches a Date property from a custom object in custom code and returns this.

Screenshot 2024-06-07 at 10.37.39.png

 

This steps works like a charm, returning the expected value when I test it.

 

Screenshot 2024-06-07 at 10.37.16.png

 

Now at a later point in the same workflow, I try to format the date for display purposes, depending on conversation language, so there's multiple branches doing a different formatting each. Since event_start is a Date (tried Datetime as well), I assumed I can use a Format data step like this:

 

Screenshot 2024-06-07 at 10.40.27.png

 

But this step fails when the workflow runs. Its kinda hard to debug, because the log just says "Action failed" without any more details. I assume that somehow the format of event_start does not match the expectations of the Format data step.

 

Before I now replace the Format data step by another custom code, I would be curious whether I'm doing something wrong or whether this is indeed not possible this way 🤔

0 Upvotes
1 Accepted solution
Jnix284
Solution
Hall of Famer | Elite Partner
Hall of Famer | Elite Partner

Fetch and format date in Workflow

SOLVE

@svamann you said that it doesn't matter if you use Date or DateTime, but there is a differentiation in the backend - how is start_date defined? Is it a date picker (date) or DateTime?

 

Here's the dev doc for Date vs DateTime - I think this is the source of the error


If my reply answered your question please mark it as a solution to make it easier for others to find.



Jennifer Nixon - Delivery Lead at Aptitude 8

connect with Jen on Linkedin

View solution in original post

0 Upvotes
8 Replies 8
PamCotton
Community Manager
Community Manager

Fetch and format date in Workflow

SOLVE

Hey @svamann, Happy Friday!

 

It looks like you're encountering an issue with formatting a date in your workflow. Ensure that the date format returned by your custom code matches the expected format for the Format data step. The Format data step might require a specific date format (e.g., ISO 8601).

 

To our top experts @danmoyle and @HFisher7 do you have any recommendations for @svamann matter?

 

Thank you,

 

Pam 

Você sabia que a Comunidade está disponível em outros idiomas?
Participe de conversas regionais, alterando suas configurações de idioma !


Did you know that the Community is available in other languages?
Join regional conversations by changing your language settings !




0 Upvotes
danmoyle
Most Valuable Member | Elite Partner
Most Valuable Member | Elite Partner

Fetch and format date in Workflow

SOLVE

Honestly I'd tag in @Jnix284 on this one. I think she's done some custom coding in workflows - more than me, anyway! 

 

Did my answer help? Please "mark as a solution" to help others find answers. Plus I really appreciate it!


Dan Moyle

HubSpot Advisor

LearningOps | Impulse Creative

emailAddress
dan@impulsecreative.com
website
https://impulsecreative.com/
Jnix284
Hall of Famer | Elite Partner
Hall of Famer | Elite Partner

Fetch and format date in Workflow

SOLVE

Thanks for the tag @danmoyle and I apologize for the delayed response @svamann - were you able to solve the issue with your CCA?


If my reply answered your question please mark it as a solution to make it easier for others to find.



Jennifer Nixon - Delivery Lead at Aptitude 8

connect with Jen on Linkedin

0 Upvotes
svamann
Participant

Fetch and format date in Workflow

SOLVE
I worked around it with custom code. Works, but I would sure like to understand why the formatting action fails… would be much more convenient to just use the native formatting action!
0 Upvotes
Jnix284
Hall of Famer | Elite Partner
Hall of Famer | Elite Partner

Fetch and format date in Workflow

SOLVE

I'm glad you found a solution @svamann, without rebuilding the workflow and CCA, it'd be hard to say why it failed based on the info provided. 


If my reply answered your question please mark it as a solution to make it easier for others to find.



Jennifer Nixon - Delivery Lead at Aptitude 8

connect with Jen on Linkedin

0 Upvotes
svamann
Participant

Fetch and format date in Workflow

SOLVE

So what information would you need to answer this?

 

I'm fetching the date property from the API in my custom code.

Screenshot 2024-06-19 at 08.41.15.png

and return the value as is

Screenshot 2024-06-19 at 08.42.12.png

The return type is declared as Date (using DateTime, makes no difference). And displays as "2024-06-12" when I test the step (see the screenshot in my original post above).

 

This output I seen directly feed into the format-date action.

 

From the above a gather that this might be an issue of the data format. I assumed that any "Date" would fit into a format date step and I can't find any explicit requirement on the date format of such a step. If there is, I'd appreciate a pointer!

0 Upvotes
Jnix284
Solution
Hall of Famer | Elite Partner
Hall of Famer | Elite Partner

Fetch and format date in Workflow

SOLVE

@svamann you said that it doesn't matter if you use Date or DateTime, but there is a differentiation in the backend - how is start_date defined? Is it a date picker (date) or DateTime?

 

Here's the dev doc for Date vs DateTime - I think this is the source of the error


If my reply answered your question please mark it as a solution to make it easier for others to find.



Jennifer Nixon - Delivery Lead at Aptitude 8

connect with Jen on Linkedin

0 Upvotes
svamann
Participant

Fetch and format date in Workflow

SOLVE

@Jnix284 it's a date picker. Choosing either Date or DateTime for the custom code output does not make an observable difference in the output I see when testing the custom code action (it's "yyyy-mm-dd" in both cases) and in the error I see from the format date action. There may, of course, be a difference in what happens under the hood.

 

Thanks for the link, it explains the output format of the API, which matches what I see when testing my custom code action. Is there also documentation on the expected input format of the format date action?

 

I always thought it's just not possible to create DateTime custom properties at all, now I learned it's possible via the API! Thanks for this insight 🙂

0 Upvotes