Fetch and format date in Workflow

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

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

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:

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 :thinking:

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

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

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

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!

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.

So what information would you need to answer this?

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

and return the value as is

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!

@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

@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 :slightly_smiling_face:

I just figured this out at last. The custom code (Python in my case) needs to return the date as a timestamp in milliseconds and ensure that it is an integer. As in

int(mydatetime.timestamp() * 1000)

Then returning this from the custom code as a “Date” and using it in a Format Date action or writing it to a DatePicker property does work.

See also this community thread.