Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,364,059
Community Members
 
Community Events
168
Community Groups

JSON date and time string to DateTime with smart values?

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

0 votes
Answer accepted
Nir Haimov Community Leader Apr 07, 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 "/"

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 Apr 08, 2021

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

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

Screenshot:

grab.png

Nir Haimov Community Leader Apr 08, 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 :)

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

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

Atlassian Community Events