JSON date and time string to DateTime with smart values?

Sam Lander April 7, 2021

I'm using Jira automation.

The incoming JSON on a webhook has "2021-11-23 23:45" in it.

I'd like to splat it into a customfield as a DateTime

So far, my attempts have yielded either a action failure or no data.

Best-guess I have is this, but that results in an empty field...

{{webhookData."Date and Time of Incident".toDateTime("yyyy-MM-dd HH:mm")}}

 

1 answer

1 accepted

1 vote
Answer accepted
Nir Haimov
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 7, 2021

Hi @Sam Lander 

Try ".toDateTime.as("yyyy-MM-dd HH:mm")

Try first to print it to the automation log, see if you get the result you want, then try to set it to a field.

Note that in order to set it to a field the format must be exactly as your dateTime customfields look like, make sure if you need use "-" or "/"

Sam Lander April 8, 2021

Thanks for the suggestion @Nir Haimov 

I get 

Error creating issueError parsing time: 2021-04-12 14:23.toDateTime.as("yyyy-MM-dd HH:mm")}} (customfield_10032)

or

Error creating issueError parsing time: 2021-04-12 14:23.toDateTime("yyyy-MM-dd HH:mm")}} (customfield_10032)

 

using either method.

Nir Haimov
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 8, 2021

@Sam Lander can you send screenshot of the automation, so we can see exactly how look what you wrote?

Sam Lander April 8, 2021

Thanks for pointing out the "Log Action", that made my life eeasier.

Screenshot:

grab.png

Nir Haimov
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 8, 2021

No problem :)

According to the documentations, 

The following functions can be used to convert a date to a date with a time component:

{{now.toStartOfDay}}
{{now.toCurrentTime}}
{{now.toDateTimeAtStartOfDay}}
{{now.toDateTimeAtStartOfDay(timezone)}}
{{now.toDateTimeAtCurrentTime}}
{{now.toDateTimeAtCurrentTime(timezone)}}

Please try them out let me know if one of them works for you, if not, send screenshot with them too :)

Sam Lander April 12, 2021

I think that this is the only possible answer. It is not so clean, because it implies stripping out the time with string ops, then adding it back into the DateTime created by blah.toDateTimeAtStartOfDay - I was hoping for something cleaner ....

I have implemented a workaround (a text field called "user-reported Time of Incident")  instead.

Like nick.kulmanovsky likes this
Nico Lenaerts August 18, 2022

Is it possible to show how you exactly did this?

I want almost exactly the same as you :-)

 

Regards,

Nico

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Site Admin
TAGS
AUG Leaders

Atlassian Community Events